Read More

Authenticate with Firebase on Android using a Phone Number

You can use Firebase Authentication to sign in a user by sending an SMS message to the user’s phone. The user signs in using a one-time code contained in the SMS message.

  1. Add Firebase to your Android project.
  2. Add the dependency for Firebase Authentication to your app-level build.gradle file:

  3. If you haven’t yet connected your app to your Firebase project, do so from the Firebase console.
  4. If you haven’t already set your app’s SHA-1 hash in the Firebase console, do so. See Authenticating Your Client for information about finding your app’s SHA-1 hash.

Create a custom layout for register user contact number, user can verify the authentication code.

Then pass the phone number to PhoneAuthProvider.verifyPhoneNumber method to request the Firebase to verify the contact number. For example:

When you call PhoneAuthProvider.verifyPhoneNumber, you must also provide an instance of OnVerificationStateChangedCallbacks, which contains implementations of the callback functions that handle the results of the request. For example:

After the user enters the verification code that Firebase sent to the user’s phone, create a PhoneAuthCredential object, using the verification code to onCodeSent or onCodeAutoRetrievalTimeOut callback.

After user verify it’s authentication code pass the credential instanace of PhoneAuthProvider to signInWithPhoneAuthCredential(credential) method.

 

Keep Coding and Keep Sharing 🙂

 

. . .

Comments (3)

Add Your Comment

  • sam s
    how to retrive hose phone number from authentication to databse
  • Oneil Bogle
    how can i extend this to create a 2 page verification
    • Manish
      Either you can create two separte activity for that or two fragment.
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close