问题:点击微信后只执行onstart()方法
解决:回调WXEntryActivity这个方法的包名必须和项目的包名一致,如项目包名com.yan.mmd 那么此方法的包名必须写成com.yan.mmd.wxapi
总结:
1 申请appid secret
UMWXHandler wxHandler = new UMWXHandler(LoginActivity.this,"wx4e042a068f1d21c0","666bc59b1d922b430a7f847d4af1cebb");
2添加授权
wxHandler.setRefreshTokenAvailable(false);//为了每次登录都有提示登录界面
wxHandler.addToSocialSDK();
3mainifirst里面必须回调
<!-- 微信回调activity -->
<activity
android:name="com.yan.mengmengda.wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
4微信后台必须填写包名和签名
5登陆
public void LoginWeiXin() {
mController.doOauthVerify(LoginActivity.this, SHARE_MEDIA.WEIXIN,
new UMAuthListener() {
@Override
public void onError(SocializeException e,
SHARE_MEDIA platform) {
}
@Override
public void onComplete(Bundle value, SHARE_MEDIA platform) {
if (value != null
&& !TextUtils.isEmpty(value.getString("uid"))) {
Toast.makeText(LoginActivity.this, "登录成功 正在加载...",
Toast.LENGTH_SHORT).show();
mController.getPlatformInfo(LoginActivity.this,
SHARE_MEDIA.WEIXIN, new UMDataListener() {
@Override
public void onStart() {
}
@Override
public void onComplete(int status,
Map<String, Object> info) {
String tencentToken = "";
String uid = "";
// 成功获取平台信息
if (status == 200 && info != null) {
StringBuilder sb = new StringBuilder();
Set<String> keys = info
.keySet();
for (String kStr : keys) {
sb.append(kStr
+ "="
+ info.get(kStr)
.toString()
+ "\r\n");
if (kStr.equals("access_token")) {
tencentToken = info
.get(kStr)
.toString();
} else if (kStr
.equals("uid")) {
uid = info.get(kStr)
.toString();
}
}
UserUtil.thirdLogin(
LoginActivity.WEIXIN_THIRDLOGIN_SIGN,
uid, tencentToken,
null, h);
Log.e("yan",
"平台信息" + sb.toString());
} else {
Log.e("yan", "发生错误");
}
}
});
} else {
Toast.makeText(LoginActivity.this, "登录失败",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancel(SHARE_MEDIA platform) {
}
@Override
public void onStart(SHARE_MEDIA platform) {
}
});
}
6退出登录时要注销