Read More
Read now

Authenticate with Firebase on Android using a Phone Number

Save

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 🙂

 

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


3 comments

  • 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

    Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

    Deniel Kerr

    Owner and Founder. Opencart

    Talk to Sales
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home