• Android 第三方内容分享旧版


    1. 清单文件的配置
     1    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     2     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
     3     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     4     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     5     <uses-permission android:name="android.permission.INTERNET" />
     6     <uses-permission android:name="android.permission.READ_LOGS" />
     7     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
     8     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     9     <uses-permission android:name="android.permission.GET_TASKS" />
    10     <uses-permission android:name="android.permission.SET_DEBUG_APP" />
    11     <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    12     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    13     <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    14     <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
    15 
    16     <application
    17         android:name="com.example.renkai.MyApp"//自建的application类继承application
    18         android:allowBackup="true"
    19         android:icon="@drawable/ic_launcher"
    20         android:label="@string/app_name"
    21         android:theme="@style/AppTheme" >
    22 <meta-data 23 android:name="UMENG_APPKEY" 24 android:value="4eaee02c527015373b000003" > 25 </meta-data> 26 27 <activity 28 android:name="com.tencent.tauth.AuthActivity" 29 android:launchMode="singleTask" 30 android:noHistory="true" > 31 <intent-filter> 32 <action android:name="android.intent.action.VIEW" /> 33 34 <category android:name="android.intent.category.DEFAULT" /> 35 <category android:name="android.intent.category.BROWSABLE" /> 36 37 <data android:scheme="tencent100424468" /> 38 </intent-filter> 39 </activity>
    40 <activity 41 android:name="com.tencent.connect.common.AssistActivity" 42 android:screenOrientation="portrait" 43 android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    44 <activity 45 android:name="com.umeng.socialize.editorpage.ShareActivity" 46 android:excludeFromRecents="true" 47 android:theme="@style/Theme.UMDefault" />

     

    2.继承的Application类

     1 public class MyApp extends Application {
     2     @Override
     3     public void onCreate() {
     4         // TODO Auto-generated method stub
     5         super.onCreate();
     6         PlatformConfig.setQQZone("100424468",
     7                 "c7394704798a158208a74ab60104f0ba");
     8         // QQ和Qzone appid appkey
     9     }
    10 }

    3.事件的使用

      

     1 public class MainActivity extends Activity {
     2 
     3     private UMShareAPI mShareAPI;
     4 
     5     @Override
     6     protected void onCreate(Bundle savedInstanceState) {
     7         super.onCreate(savedInstanceState);
     8         setContentView(R.layout.activity_main);
     9     }
    10 
    11     public void login(View v) {
    12         mShareAPI = UMShareAPI.get(this);
    13         SHARE_MEDIA platform = SHARE_MEDIA.QQ;
    14         mShareAPI.doOauthVerify(this, platform, umAuthListener);
    15     }
    16 
    17     public void share(View v) {
    18         UMImage image = new UMImage(MainActivity.this,
    19                 "http://www.umeng.com/images/pic/social/integrated_3.png");
    20         final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[] {
    21                 SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,
    22                 SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE,
    23                 SHARE_MEDIA.DOUBAN };
    24         new ShareAction(this).setDisplayList(displaylist).withText("刘杰")
    25                 .withTitle("大屌丝").withTargetUrl("http://www.baidu.com")
    26                 .withMedia(image).setListenerList(new UMShareListener() {
    27                     @Override
    28                     public void onResult(SHARE_MEDIA platform) {
    29                         Toast.makeText(MainActivity.this, platform + " 分享成功啦",
    30                                 Toast.LENGTH_SHORT).show();
    31                     }
    32 
    33                     @Override
    34                     public void onError(SHARE_MEDIA platform, Throwable t) {
    35                         Toast.makeText(MainActivity.this, platform + " 分享失败啦",
    36                                 Toast.LENGTH_SHORT).show();
    37                     }
    38 
    39                     @Override
    40                     public void onCancel(SHARE_MEDIA platform) {
    41                         Toast.makeText(MainActivity.this, platform + " 分享取消了",
    42                                 Toast.LENGTH_SHORT).show();
    43                     }
    44                 }).open();
    45     }
    46 
    47     @Override
    48     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    49         super.onActivityResult(requestCode, resultCode, data);
    50         mShareAPI.onActivityResult(requestCode, resultCode, data);
    51         UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    52     }
    53 
    54     private UMAuthListener umAuthListener = new UMAuthListener() {
    55         @Override
    56         public void onComplete(SHARE_MEDIA platform, int action,
    57                 Map<String, String> data) {
    58             Toast.makeText(getApplicationContext(), "Authorize succeed",
    59                     Toast.LENGTH_SHORT).show();
    60         }
    61 
    62         @Override
    63         public void onError(SHARE_MEDIA platform, int action, Throwable t) {
    64             Toast.makeText(getApplicationContext(), "Authorize fail",
    65                     Toast.LENGTH_SHORT).show();
    66         }
    67 
    68         @Override
    69         public void onCancel(SHARE_MEDIA platform, int action) {
    70             Toast.makeText(getApplicationContext(), "Authorize cancel",
    71                     Toast.LENGTH_SHORT).show();
    72         }
    73     };
    74 }
  • 相关阅读:
    jquery通过live绑定toggle事件
    svn is already locked解决方案
    不安全代码只会在使用 /unsafe 编译的情况下出现
    eclipse 新建 java 文件时自动生成注释
    浅谈权限设计
    ie6/IE8/IE9/谷歌以及火狐等浏览器下li 高度一致解决办法
    PHP+MSSQL TEXT字段被截断的解决方案
    利用CSS让dl dt dd呈现多行多列效果
    CSS实现图片水平垂直居中于DIV
    CSS 关于IE6 margin 为负数 负值的时候 正常显示的方法
  • 原文地址:https://www.cnblogs.com/gyqrenkai/p/1234567890kaikai.html
Copyright © 2020-2023  润新知