Android源碼下載:QQ第三方登入demo
功能分類:其他
支援平台: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();
- }
- }
源碼:http://down.51cto.com/data/1976923