第一步:
新建项目的时候 包名(必须一致,不然没有)
com.umeng.soexample
该去 友盟第三方下载的 jar 包 都下载好
然后 把values 中的 文件 都复制了
layout 中的文件都复制了
别忘了把图片的文件也都复制完
第二步:
上代码:权限
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
上代码:配置 写在 清单文件列表 中 application 标签内 标签外 独立
<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:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="orientation|keyboardHidden|screenSize"/>
上代码:配置2
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
上代码:Applicton
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
UMConfigure.setLogEnabled(true);
UMConfigure.init(this,"5a12384aa40fa3551f0001d1"
,"umeng", UMConfigure.DEVICE_TYPE_PHONE, "");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0
//打log
UMConfigure.setLogEnabled(true);
PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0");
PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
UMShareAPI.get(this);
}
}
上代码:Applicton
//全局化 这个变量
private UMShareAPI umShareAPI;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
umShareAPI = UMShareAPI.get(this);
}
//这个方法要放在Activity 中去
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
}
//-----------------------------------------通过一个按钮触发监听--------------------------------------------------
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn:
UMShareConfig shareConfig = new UMShareConfig();
shareConfig.isNeedAuthOnGetUserInfo(true);
UMShareAPI.get(MainActivity.this).setShareConfig(shareConfig);
umShareAPI.getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, authListener);
break;
}
}
//-----------------------------------------------给这个第三方一个监听-------------------------------------------------
public UMAuthListener authListener = new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA share_media) {
}
@Override
public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
mTv.setText(map.toString());
Picasso.with(MainActivity.this).load(map.get("profile_image_url")).into(mImg);
Log.i("quni ma de ", map.toString());
}
@Override
public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
}
@Override
public void onCancel(SHARE_MEDIA share_media, int i) {
}
};