Download Android source code: QQ third-party logon demo
Function category: Others
Supported platforms: Android
Runtime Environment: Eclipse
Development language: Java
Development tools: Eclipse
Source code size: 1.31 MB
Source code:Http://down.51cto.com/data/1976923
Source code Introduction
Recently, I used a third-party logon. QQ has many classes in the official demo. Here I upload a small demo. There are only two classes. I can authorize QQ to log on to a third party.
Source code running
Authorized logon page
Return Value for successful authorization
Home Page
Source code snippets
- 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 (),
- "Logon successful ");
- 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 ();
- }
- }
Source code:Http://down.51cto.com/data/1976923