Go to console

PhoneAuthProvider

public class PhoneAuthProvider extends Object

Represents the phone number authentication mechanism. Use this class to obtain PhoneAuthCredentials.

Nested Class Summary

class PhoneAuthProvider.ForceResendingToken A 'token' that can be used to force re-sending an SMS verification code. 
class PhoneAuthProvider.OnVerificationStateChangedCallbacks Registered callbacks for the different phone auth events. 

Constant Summary

String PHONE_SIGN_IN_METHOD Unique string identifier for Phone sign-in method.
String PROVIDER_ID Unique string identifier for this provider type.

Public Method Summary

static PhoneAuthCredential
getCredential(String verificationId, String smsCode)
Returns a new instance of AuthCredential that is associated with a phone number.
static PhoneAuthProvider
getInstance()
Initializes a new PhoneAuthProvider using the default FirebaseAuth instance.
static PhoneAuthProvider
getInstance(FirebaseAuth firebaseAuth)
Static method to initialize a new PhoneAuthProvider for the specified Auth instance.
void
verifyPhoneNumber(String phoneNumber, long timeout, TimeUnit unit, Activity activity, PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks)
Starts the phone number verification process for the given phone number.
void
void
void

Inherited Method Summary

Constants

public static final String PHONE_SIGN_IN_METHOD

Unique string identifier for Phone sign-in method.

Constant Value: "phone"

public static final String PROVIDER_ID

Unique string identifier for this provider type.

Constant Value: "phone"

Public Methods

public static PhoneAuthCredential getCredential (String verificationId, String smsCode)

Returns a new instance of AuthCredential that is associated with a phone number. Used when calling signInWithCredential(AuthCredential) or linkWithCredential(AuthCredential).

Parameters
verificationId a valid verificationId retrieved by calling verifyPhoneNumber(String, long, TimeUnit, Activity, OnVerificationStateChangedCallbacks)
smsCode the 6 digit SMS-code sent to the user

public static PhoneAuthProvider getInstance ()

Initializes a new PhoneAuthProvider using the default FirebaseAuth instance.

public static PhoneAuthProvider getInstance (FirebaseAuth firebaseAuth)

Static method to initialize a new PhoneAuthProvider for the specified Auth instance.

public void verifyPhoneNumber (String phoneNumber, long timeout, TimeUnit unit, Activity activity, PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks)

Starts the phone number verification process for the given phone number. Either sends an SMS with a 6 digit code to the phone number specified or triggers the callback with a complete AuthCredential that can be used to log in the user.

The specified callback will be Activity-scoped, i.e. it will be automatically removed during onStop(). This function is reentrant and can be called again in onStart(). No duplicated SMS will be sent out upon re-entry (before timeout).

Make sure to test all scenarios below:

  • You directly get back an AuthCredential if Google Play services verified the phone number instantly or helped you auto-retrieve the verification code.
  • auto-retrieve verification code timed out.
  • error cases when you receive