找着友盟的网页,自己注册一个号,在sdk文档中有步骤
1.导包:
2.权限
3.加入activity
4.添加友盟appkey
<meta-data
android:name="UMENG_APPKEY"
android:value="你的appkey" >
</meta-data>
5建立一个application文件,随便起一个名字,比如叫App,别忘了在AndroidManifest文件中配置(如果本身已有,不需要重新建立):
6在application文件中配置三方平台的appkey:
PlatformConfig.setQQZone("你的qq appid", "key");
//初始化
UMShareAPI.get(this);
//设置qq平台的id和key
PlatformConfig.setQQZone("1106163122","aYFBhRfnHWXAkrPT");
7.
/**
* 姓名:孙盼盼
* 时间:2017/5/12
* 类用途:
* 思路:
*/
public class LoginActivity extends AppCompatActivity{
private UMAuthListener umAuthListener = new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA platform) {
//授权开始的回调
}
@Override
public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {
Toast.makeText(getApplicationContext(), "Authorize succeed", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(SHARE_MEDIA platform, int action, Throwable t) {
Toast.makeText( getApplicationContext(), "Authorize fail", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel(SHARE_MEDIA platform, int action) {
Toast.makeText( getApplicationContext(), "Authorize cancel", Toast.LENGTH_SHORT).show();
}
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UMShareAPI umShareAPI = UMShareAPI.get(this);
umShareAPI.getPlatformInfo(this,SHARE_MEDIA.QQ,umAuthListener);
}
@Override
回传值
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
}
}
授权失败解决方法:qq平台的id和key 换换,
//设置qq平台的id和key
PlatformConfig.setQQZone("1106086069","BbUDh6t7rYjJWowh");