Download Android source code: QQ third-party logon demo

Source: Internet
Author: User

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

 
 
  1. Handler mHandler = new Handler (){
  2. @ Override
  3. Public void handleMessage (Message msg ){
  4. If (msg. what = 0 ){
  5. JSONObject response = (JSONObject) msg. obj;
  6. If (response. has ("nickname ")){
  7. Try {
  8. MUserInfo. setVisibility (android. view. View. VISIBLE );
  9. MUserInfo. setText (response. getString ("nickname "));
  10. } Catch (JSONException e ){
  11. // TODO Auto-generated catch block
  12. E. printStackTrace ();
  13. }
  14. }
  15. } Else if (msg. what = 1 ){
  16. Bitmap bitmap = (Bitmap) msg. obj;
  17. MUserLogo. setImageBitmap (bitmap );
  18. MUserLogo. setVisibility (android. view. View. VISIBLE );
  19. }
  20. }
  21. };
  22. Private void onClickLogin (){
  23. If (! MQQAuth. isSessionValid ()){
  24. IUiListener listener = new BaseUiListener (){
  25. @ Override
  26. Protected void doComplete (JSONObject values ){
  27. UpdateUserInfo ();
  28. UpdateLoginButton ();
  29. }
  30. };
  31. MQQAuth. login (this, "all", listener );
  32. // MTencent. loginWithOEM (this, "all ",
  33. // Listener, "10000144", "10000144", "xxxx ");
  34. MTencent. login (this, "all", listener );
  35. } Else {
  36. MQQAuth. logout (this );
  37. UpdateUserInfo ();
  38. UpdateLoginButton ();
  39. }
  40. }
  41. Public static boolean ready (Context context ){
  42. If (mQQAuth = null ){
  43. Return false;
  44. }
  45. Boolean ready = mQQAuth. isSessionValid ()
  46. & MQQAuth. getQQToken (). getOpenId ()! = Null;
  47. If (! Ready)
  48. Toast. makeText (context, "login and get openId first, please! ",
  49. Toast. LENGTH_SHORT). show ();
  50. Return ready;
  51. }
  52. Private class BaseUiListener implements IUiListener {
  53. @ Override
  54. Public void onComplete (Object response ){
  55. Util. showResultDialog (MainActivity. this, response. toString (),
  56. "Logon successful ");
  57. DoComplete (JSONObject) response );
  58. }
  59. Protected void doComplete (JSONObject values ){
  60. }
  61. @ Override
  62. Public void onError (UiError e ){
  63. Util. toastMessage (MainActivity. this, "onError:" + e. errorDetail );
  64. Util. dismissDialog ();
  65. }
  66. @ Override
  67. Public void onCancel (){
  68. Util. toastMessage (MainActivity. this, "onCancel :");
  69. Util. dismissDialog ();
  70. }
  71. }

Source code:Http://down.51cto.com/data/1976923

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.