简体   繁体   中英

Twitter Digits : how to check if the user is already registered

I am experimenting with Digits API by Twitter for registering users on my Android application. Currently in my launching activity I display a button( com.digits.sdk.android.DigitsAuthButton ) that asks for users to enter their phone number so that a confirmation code could be sent. Once they enter the confirmation code and are authenticated, I receive a user_id in the callback method.

Now, next time if I click on the same button in the launching activity it doesn't display the option to enter the phone number and just returns back the same user_id which was already registered.

I want to replicate this same thing in my Java code without that extra click of the com.digits.sdk.android.DigitsAuthButton button. I had a look at some samples and they use the following statement to verify the same:

if (Digits.getSessionManager().getActiveSession() != null) { ... }

Is this sufficient or should I use sharedPreference to store the returned user_id with the phone number too ?

Update

Personally i'm using sharedpreference it works well for me..

as for handling "change in phone number later on" you can create a log out Button to turn a preference from true to false.

Or

you can check change in phone number:

TelephonyManager tMgr =     (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();

//Required Permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/> 

I know its late but may be helpful for a beginner.To verify that the session is already active, please put this code in your onCreate of that activity in which Digits phone number verification button is initialised:

    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
            Fabric.with(this, new TwitterCore(authConfig), new Digits.Builder().build());
    if (Digits.getActiveSession() != null) {
                Intent ss = new Intent(CurrentActivity.this, SecondActivity.class);
                startActivity(ss);
                finish();
            }

And whenever you want to retrive phone number then call :

String phone = Digits.getActiveSession().getPhoneNumber();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM