Android record 22-logic processing of account bindings in development

Source: Internet
Author: User

Android record 22-logic processing of account bindings in developmentreprint Please specify: It_xiao WizardBlog address: http://blog.csdn.net/wwj_748 Preface

This blog to share with you is the development of the account binding we often meet the development of the function, we first to consider a few questions:

1. Why should I have an account binding?

2. How does it differ from third-party logins?

3. How to deal with the logic of account binding?

Well, with these three questions, let's develop an account binding function for our app. Let's show you one:

Previously shared blog posts about third-party logins, shared implementations: http://blog.csdn.net/wwj_748/article/details/41117173, you can look first, How to use third-party SDK to implement third-party login functions.

Why do I have to have an account binding?

Account binding is also one of the means of social entry, in order to make it easier for users to share in-app resources into his social circle, to reduce the user's frequent input account login operations, the other platform users into the application of the user's approach.

What is the difference between an account binding and a third-party login?

The main logic is the difference, third-party login is actually to let users enjoy the pleasure of a key login, and do not need to remember any account and password, this user experience is to meet the user is easy to forget the use of the different platform account and password, to avoid the cumbersome and thankless registration process, It's also easier to turn users of social platforms into their own in-app users. Account binding has been said before, is to make it easier for users to share.

how to deal with the logic of account binding?

Here is a point, account binding and third-party login is to go through the authorization process, so that the logic behind them is the same, but it is in our application logic is not the same.

Two cases:

1. The account is not logged in, the binding status is not displayed

2. Account login, Show account binding status

The user can choose to use a third-party login, and once the login is successful, one of the platforms is already bound.

We can see that the QQ account has been bound successfully. Here is a little forgot to say, how to calculate the binding account success?

Whether it is a third-party login or Account binding has a process of generating accounts , and this process is required to interact with the server, through our authorized access to the third-party platform data to generate the account in our application, if the build succeeds, it means that the binding is successful.

There is a state of binding, and naturally there is the state of unbinding:


The unbind here simply changes the state of the application, does not interact with our server, and does not affect the status of our account login.

Said so much, did not see the code, you will not hit me, the dead, hit the face, face hurt self-esteem, good or bad.

The following is an account binding using the Friends Union:

The entire platform controller, responsible for the management of the entire SDK configuration, operation and other processing private umsocialservice Mcontroller = Umservicefactory.getumsocialservice ( Appconstants.descriptor);

/** * Configure share platform parameters */private void Configplatforms () {//Add Sina SSO Authorization Mcontroller.getconfig (). Setssohandler (New Sinassohandler ( );//Mcontroller.getconfig (). Setsinacallbackurl ("Http://sns.whalecloud.com/sina2/callback");//Add QQ, Qzone platform Addqqplatform ();} private void Addqqplatform () {String appId = appconstants.qqzone_appid; String AppKey = appconstants.qqzone_appkey;//add QQ support, and set the target of QQ share content urlumqqssohandler Qqssohandler = new Umqqssohandler (Settingactivity.this,appid, AppKey); Qqssohandler.settargeturl ("http://www.umeng.com"); QQSSOHANDLER.ADDTOSOCIALSDK ();}

To handle a click event in the OnClick method:



Login method

/** * Authorized. If the authorization is successful, obtain the user information * * @param platform */private Void Login (final Share_media platform) {mcontroller.dooauthverify (SETTINGAC Tivity.this, Platform,new Umauthlistener () {@Overridepublic void OnStart (Share_media platform) {Logutils.logi (TAG, " OnStart------"+ thread.currentthread (). GetId ()); Toastutils.showshort (settingactivity.this,getstring (R.string.oauth_begin));} @Overridepublic void OnError (socializeexception E,share_media platform) {Logutils.logi (TAG, "onError------" + Thread.CurrentThread (). GetId ()); Toastutils.showshort (settingactivity.this,getstring (R.string.oauth_fail));} @Overridepublic void OnComplete (Bundle value, Share_media platform) {Logutils.logi (TAG, "oncomplete------" + Thread.CurrentThread (). GetId ());//get uidstring uid = value.getstring ("UID"); if (value! = NULL &&!). Textutils.isempty (UID)) {//UID not empty, get user information GetUserInfo (platform);} else {Toastutils.showshort (settingactivity.this, GetString (R.string.oauth_fail));}} @Overridepublic void OnCancel (Share_media platform) {Logutils.logi (TAG, "onCancel------" + thread.currentthread (). GetId ()); Toastutils.showshort (settingactivity.this,getstring (r.string.oauth_cancle));});}

Get platform Information

/** * Get user information * * @param platform */private Void GetUserInfo (final Share_media platform) {mcontroller.getplatforminfo (sett Ingactivity.this, Platform,new Umdatalistener () {@Overridepublic void OnStart () {//start getting Showprogressdialog ();} @Overridepublic void oncomplete (int status, map<string, object> info) {Logutils.logi ("third login", info.tostring ()); String sns_id = ""; String Sns_avatar = ""; String sns_loginname = ""; if (info! = null) {String SNS = ""; if (platform = = Share_media. SINA) {//Sina Weibo SNS = "SINA"; sns_id = Info.get ("UID"). ToString (); Sns_avatar = Info.get ("Profile_image_url"). ToString (); Sns_loginname = Info.get ("Screen_name"). toString ();} else if (platform = = Share_media. QQ) {//Qqsns = "QQ"; sns_id = Info.get ("UID"). ToString (); Sns_avatar = Info.get ("Profile_image_url"). ToString (); sns_ LoginName = Info.get ("Screen_name"). toString ();} else if (platform = = Share_media. Weixin) {//SNS = "WeChat"; sns_id = Info.get ("OpenID"). ToString (); Sns_avatar = Info.get ("Headimgurl"). ToString (); sns_loginname = Info.get ("nickname"). toString ();} else if (platform = = Share_media. Douban) {//watercress SNS = "Douban"; sns_id = Info.get ("UID"). ToString (); Sns_avatar = Info.get ("Profile_image_url"). ToString () ; sns_loginname = Info.get ("Screen_name"). toString ();} Logutils.loge ("Weixin", SNS + "," + sns_id + "," + sns_loginname); Httprequesthelper.getinstance (). Getuserbysns (settingactivity.this,sns,sns_id,sns_avatar,sns_loginname,new Getuserbysnsresponse (Platform, sns,sns_id, Sns_avatar, Sns_loginname));}});


Unbind method

/** * Logout of this login * * @param platform */private Void Logout (final Share_media platform) {Mcontroller.deleteoauth (Settingactivity.this, Platform,new Socializeclientlistener () {@Overridepublic void OnStart () {} @Overridepublic void oncomplete (int status, Socializeentity entity) {String Showtext = "Release" + platform.tostring () + "platform authorization succeeded"; if (status! = Statuscode.st_code_successe D) {showtext = "release" + platform.tostring () + "platform authorization failed [" + Status + "]";} else {if (platform = = Share_media. SINA) {Sinabindingtext.settext (getString (R.string.setting_unbind)); Storageutils.setsharevalue (settingactivity.this,storageutils.key_sina_binding, false);} else if (platform = = Share_media. QQ) {Qqbindingtext.settext (getString (R.string.setting_unbind)); Storageutils.setsharevalue (settingactivity.this,storageutils.key_qq_binding, False);}} Toast.maketext (Settingactivity.this, Showtext,toast.length_short). Show ();}}); 

Cancel dialog box

/** * Show unbind dialog box */private void Showcanclebindingdialog (final Share_media platform) {final Exitdialog exitdialog = new Exit Dialog (Settingactivity.this); Exitdialog.setexittext (GetString (r.string.tip_cancle_binding)); Exitdialog.setitemclicklistener (New Exitdialog.itemclicklistener () {@Overridepublic void Onitemclick (view view, int Index) {Exitdialog.dismiss (), if (index = = 0) {logout (platform);}}); if (!exitdialog.isshowing () &&!isfinishing ()) {exitdialog.show ();}}

Here is the entire implementation of the logic, please do not call me to demo, more hands-on, with a bit of brain, I believe you will soon be able to implement this feature.


Android record 22-logic processing of account bindings in development

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.