- 清单文件的配置
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 }