功能分类:其他
支持平台:Android
运行环境:Eclipse
开发语言:Java
开发工具:Eclipse
源码大小:1.31MB
源码下载地址:http://down.51cto.com/data/1976923
源码简介
最近使用第三方登录,QQ登录官方给的demo中类太多了,这里上传一个小demo,只有2个类,可以授权QQ进行第三方登录。
源码运行截图
授权登录界面
授权成功返回值
主页面
源码片段
Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 0) {
JSONObject response = (JSONObject) msg.obj;
if (response.has("nickname")) {
try {
mUserInfo.setVisibility(android.view.View.VISIBLE);
mUserInfo.setText(response.getString("nickname"));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else if (msg.what == 1) {
Bitmap bitmap = (Bitmap) msg.obj;
mUserLogo.setImageBitmap(bitmap);
mUserLogo.setVisibility(android.view.View.VISIBLE);
}
}
};
private void onClickLogin() {
if (!mQQAuth.isSessionValid()) {
IUiListener listener = new BaseUiListener() {
@Override
protected void doComplete(JSONObject values) {
updateUserInfo();
updateLoginButton();
}
};
mQQAuth.login(this, "all", listener);
// mTencent.loginWithOEM(this, "all",
// listener,"10000144","10000144","xxxx");
mTencent.login(this, "all", listener);
} else {
mQQAuth.logout(this);
updateUserInfo();
updateLoginButton();
}
}
public static boolean ready(Context context) {
if (mQQAuth == null) {
return false;
}
boolean ready = mQQAuth.isSessionValid()
&& mQQAuth.getQQToken().getOpenId() != null;
if (!ready)
Toast.makeText(context, "login and get openId first, please!",
Toast.LENGTH_SHORT).show();
return ready;
}
private class BaseUiListener implements IUiListener {
@Override
public void onComplete(Object response) {
Util.showResultDialog(MainActivity.this, response.toString(),
"登录成功");
doComplete((JSONObject) response);
}
protected void doComplete(JSONObject values) {
}
@Override
public void onError(UiError e) {
Util.toastMessage(MainActivity.this, "onError: " + e.errorDetail);
Util.dismissDialog();
}
@Override
public void onCancel() {
Util.toastMessage(MainActivity.this, "onCancel: ");
Util.dismissDialog();
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.