1.按步骤导入该导入的东西
2.在你的Application里面写入:
UMConfigure.init(this,"5a12384aa40fa3551f0001d1","umeng",UMConfigure.DEVICE_TYPE_PHONE,"");
PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
3.设置点击事件
UMShareAPI umShareAPI = UMShareAPI.get(MainActivity.this);
umShareAPI.getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA share_media) {
}
@Override
public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
String name = map.get("screen_name");
//获取头像
String img = map.get("profile_image_url");
Intent intent = new Intent(MainActivity.this,SucessActivity.class);
intent.putExtra("name",name);
startActivity(intent);
finish();
}
@Override
public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
}
@Override
public void onCancel(SHARE_MEDIA share_media, int i) {
}
});
4.清单文件中配置,如下:
<!-- 3.写以下两个activity -->
<activity
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tencent100424468" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.connect.common.AssistActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="orientation|keyboardHidden|screenSize"/>
<!-- 3.写以下配置 -->
<meta-data android:name="UMENG_APPKEY"
android:value="5c07d385f1f556e5f90003c4">
</meta-data>
5.权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_LOGS"
tools:ignore="ProtectedPermissions" />
6.记得写回调的方法!!
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
UMShareAPI.get(this).onActivityResult(requestCode,resultCode,data);
}