4

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 ?

pankaj
  • 1,316
  • 3
  • 16
  • 27

2 Answers2

1

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"/> 
Mounir Elfassi
  • 2,242
  • 3
  • 23
  • 38
  • I had a look at this code, this is a session recorder to probably track logins after the success callback is triggered. My question is about checking the status of registration , the snippet i have posted as a checker is also from the same sample. – pankaj Aug 30 '15 at 09:35
  • so you need to check if the user already logged in, if yes he wont see login button? – Mounir Elfassi Aug 30 '15 at 09:45
  • Yes, one way is to rely on Digits.sessionmanager.getactivesession() , another way is to use sharedpreference in my App once the success callback is called (similar to what you have suggested). I am confused as to which one to use , and how would it handle change in phone number later on. – pankaj Aug 30 '15 at 09:48
  • What all do you think I should store in the sharedPreferences ? I am thinking of storing only 'user_id' and 'phonenumber'. – pankaj Aug 30 '15 at 10:23
  • yes @pankaj store them + true or false would do it! – Mounir Elfassi Aug 30 '15 at 10:40
0

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();

Dr. Abhishek
  • 158
  • 1
  • 11