Dale
Dale

Reputation: 619

How to use Android Firebase Phone Authentiation

How do you use Android Firebase phone authentication with the first Activity holding the form that gets the phone number of the user, and the second Activity processes the confirmation code.

Upvotes: 0

Views: 431

Answers (2)

Isabella Chen
Isabella Chen

Reputation: 2411

Dale, I'd recommend one Activity and two Fragments for UI transition and you only do verifyPhoneNumber in your Activity. Based on the callback, you can transition from PhoneNumberInputFragment to VerificationCodeInputFragment.

FirebaseUI is open sourced and you can take a look at code there: https://github.com/firebase/FirebaseUI-Android/tree/master/auth/src/main/java/com/firebase/ui/auth/ui/phone

If you really want 2 Activity for whatever reason:

  1. Call verifyPhoneNumber in 1st Activity and use the Activity-scoped listener:

a) if onVerificationComplete is called back (instant validation), skip 2nd Activity b) if onCodeSent is called back, transition to 2nd Activity

2 b) Since 2nd Activity is started & 1st Activity is stopped, the listener of the 1st Activity is auto-detached. In 2nd Activity, call verifyPhoneNumber again. Google Play services will keep the session alive and no 2nd SMS will be sent. You will get onCodeSent immediately with the same verificationId.

  1. In your 2nd Activity, when onVerificationComplete is called back (SMS auto-retrieval in this case), fill in the code for the user and in the background call signInWithCredential.

Upvotes: 2

JavadBadirkhanly
JavadBadirkhanly

Reputation: 645

Just research. Firebase Authentication.

Upvotes: 0

Related Questions