qq登陆
/**
* sendMessageQQ:qq分享
*
* @author huangzongwang Date:2015-5-19上午11:21:28
*/
private void sendMessageQQ(int choil) {
Bundle bundle = new Bundle();
bundle.putString(QQShare.SHARE_TO_QQ_TITLE,
getIntent().getStringExtra("title"));
bundle.putString(QQShare.SHARE_TO_QQ_SUMMARY,
ShareUtil.getShareContent(WXShareAct.this));
bundle.putString(QQShare.SHARE_TO_QQ_TARGET_URL, getIntent()
.getStringExtra("url"));
bundle.putString(QQShare.SHARE_TO_QQ_APP_NAME, "云润即时看点");
if (choil == 1) {
bundle.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, getIntent()
.getStringExtra("img"));
bundle.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE,
QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
tencent.shareToQQ(WXShareAct.this, bundle, new QQShareUtil(
WXShareAct.this));
} else {
ArrayList<String> value = new ArrayList<String>();
value.add(getIntent().getStringExtra("img"));
bundle.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, value);
bundle.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE,
QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
tencent.shareToQzone(WXShareAct.this, bundle, new QQShareUtil(
WXShareAct.this));
}
}
//qq登陆回调类,获取用户信息
public class TencentQQHelper implements IUiListener{
Activity activity;
Tencent mTencent;
String openId;
String imei;
String imsi;
public TencentQQHelper(Activity activity, Tencent mTencent,String imei,String imsi) {
super();
this.activity = activity;
this.mTencent = mTencent;
this.imei=imei;
this.imsi=imsi;
}
private void getUserInfo(UserInfo info) {
info.getUserInfo(new IUiListener() {
@Override
public void onError(UiError arg0) {
}
@Override
public void onComplete(Object response) {
JSONObject jsonObject=(JSONObject) response;
try {
MyApplication.writeData(null, null, jsonObject.getString("nickname"), "123", openId, "qq", jsonObject.getString("figureurl"), true, null);
UserCenterUtil.login("", "", imei, imsi, openId, "4", activity);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onCancel() {
}
});
}
@Override
public void onCancel() {
Toast.makeText(activity, "取消登录", Toast.LENGTH_SHORT).show();
}
@Override
public void onComplete(Object resopn) {
Toast.makeText(activity, "登录成功", Toast.LENGTH_SHORT).show();
try {
openId=((JSONObject)resopn).getString("openid");
} catch (JSONException e) {
e.printStackTrace();
}
QQToken qqToken=mTencent.getQQToken();
UserInfo info=new UserInfo(activity, qqToken);
getUserInfo(info);
}
@Override
public void onError(UiError arg0) {
Toast.makeText(activity, "登录失败", Toast.LENGTH_SHORT).show();
}
}
//唤起QQ登陆界面
tencent.login(LoginActivity.this, "all", new TencentQQHelper(
LoginActivity.this, tencent,imei,imsi));