Android记录22-关于开发中账号绑定的逻辑处理,android开发语言kotlin

S

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

tring appKey = AppConstants.QQZONE_APPKEY;

// 添加QQ支持, 并且设置QQ分享内容的target url

UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(SettingActivity.this,

appId, appKey);

qqSsoHandler.setTargetUrl(“http://www.umeng.com”);

qqSsoHandler.addToSocialSDK();

}

在Onclick方法中处理点击事件:

Android记录22-关于开发中账号绑定的逻辑处理,android开发语言kotlin

登录方法

/**

  • 授权。如果授权成功,则获取用户信息

  • @param platform

*/

private void login(final SHARE_MEDIA platform) {

mController.doOauthVerify(SettingActivity.this, platform,

new UMAuthListener() {

@Override

public void onStart(SHARE_MEDIA platform) {

LogUtils.logi(TAG, “onStart------”

  • Thread.currentThread().getId());

ToastUtils.showShort(SettingActivity.this,

getString(R.string.oauth_begin));

}

@Override

public void one rror(SocializeException e,

SHARE_MEDIA platform) {

LogUtils.logi(TAG, “onError------”

  • Thread.currentThread().getId());

ToastUtils.showShort(SettingActivity.this,

getString(R.string.oauth_fail));

}

@Override

public void onComplete(Bundle value, SHARE_MEDIA platform) {

LogUtils.logi(TAG, “onComplete------”

  • Thread.currentThread().getId());

// 获取uid

String uid = value.getString(“uid”);

if (value != null && !TextUtils.isEmpty(uid)) {

// uid不为空,获取用户信息

getUserInfo(platform);

} else {

ToastUtils.showShort(SettingActivity.this,

getString(R.string.oauth_fail));

}

}

@Override

public void onCancel(SHARE_MEDIA platform) {

LogUtils.logi(TAG, “onCancel------”

  • Thread.currentThread().getId());

ToastUtils.showShort(SettingActivity.this,

getString(R.string.oauth_cancle));

}

});

}

**

获取平台信息**

/**

  • 获取用户信息

  • @param platform

*/

private void getUserInfo(final SHARE_MEDIA platform) {

mController.getPlatformInfo(SettingActivity.this, platform,

new UMDataListener() {

@Override

public void onStart() {

// 开始获取

showProgressDialog();

}

@Override

public void onComplete(int status, Map<String, Object> info) {

LogUtils.logi(“third login”, info.toString());

String sns_id = “”;

String sns_avatar = “”;

String sns_loginname = “”;

if (info != null) {

String sns = “”;

if (platform == SHARE_MEDIA.SINA) { // 新浪微博

sns = “sina”;

sns_id = info.get(“uid”).toString();

sns_avatar = info.get(“profile_image_url”)

.toString();

sns_loginname = info.get(“screen_name”)

.toString();

} else if (platform == SHARE_MEDIA.QQ) { // QQ

sns = “qq”;

sns_id = info.get(“uid”).toString();

sns_avatar = info.get(“profile_image_url”)

.toString();

sns_loginname = info.get(“screen_name”)

.toString();

} else if (platform == SHARE_MEDIA.WEIXIN) { // 微信

sns = “wechat”;

sns_id = info.get(“openid”).toString();

sns_avatar = info.get(“headimgurl”).toString();

sns_loginname = info.get(“nickname”).toString();

} else if (platform == SHARE_MEDIA.DOUBAN) { // 豆瓣

sns = “douban”;

sns_id = info.get(“uid”).toString();

sns_avatar = info.get(“profile_image_url”)

.toString();

sns_loginname = info.get(“screen_name”)

.toString();

}

LogUtils.loge(“weixin”, sns + “,” + sns_id + “,”

  • sns_loginname);

HttpRequestHelper.getInstance().getUserBySns(

SettingActivity.this,

sns,

sns_id,

sns_avatar,

sns_loginname,

new GetUserBySnsResponse(platform, sns,

sns_id, sns_avatar, sns_loginname));

}

}

});

}

解除绑定方法

/**

  • 注销本次登陆

  • @param platform

*/

private void logout(final SHARE_MEDIA platform) {

mController.deleteOauth(SettingActivity.this, platform,

new SocializeClientListener() {

@Override

public void onStart() {

}

@Override

public void onComplete(int status, SocializeEntity entity) {

String showText = “解除” + platform.toString() + “平台授权成功”;

if (status != StatusCode.ST_CODE_SUCCESSED) {

showText = “解除” + platform.toString() + “平台授权失败[”

  • status + “]”;

} else {

if (platform == SHARE_MEDIA.SINA) {

sinaBindingText

.setText(getString(R.string.setting_unbind));

StorageUtils.setShareValue(

SettingActivity.this,

StorageUtils.KEY_SINA_BINDING, false);

} else if (platform == SHARE_MEDIA.QQ) {

qqBindingText

.setText(getString(R.string.setting_unbind));

StorageUtils.setShareValue(

SettingActivity.this,

StorageUtils.KEY_QQ_BINDING, false);

}

}

Toast.makeText(SettingActivity.this, showText,

Toast.LENGTH_SHORT).show();

}

});

}

取消对话框

/**

  • 显示取消绑定对话框

*/

private void showCancleBindingDialog(final SHARE_MEDIA platform) {

final ExitDialog exitDialog = new ExitDialog(SettingActivity.this);

exitDialog.setExitText(getString(R.string.tip_cancle_binding));

exitDialog.setItemClickListener(new ExitDialog.ItemClickListener() {

@Override

public void onItemClick(View view, int index) {

exitDialog.dismiss();

if (index == 0) {

logout(platform);

}

}

});

if (!exitDialog.isShowing() && !isFinishing()) {

上一篇:Office/Pdf格式转换,Net5环境下Aspose最新版21.8全系列,去水印等


下一篇:23 策略模式