PhoneAuthOptions.Builder

classPhoneAuthOptions.Builder


A Builder class forPhoneAuthOptions. Get an instance of this Builder usingnewBuilder ornewBuilder.

Summary

Public constructors

Creates a new Builder

Public functions

PhoneAuthOptions

Returns thePhoneAuthOptions that thisBuilder has constructed.

PhoneAuthOptions.Builder
requireSmsValidation(requireSmsValidation: Boolean)

Specifies whether to force an SMS to be sent for second factor validation.

PhoneAuthOptions.Builder
setActivity(activity: Activity)

Sets theActivity to which the callbacks are scoped, and with which app verification will be completed.

PhoneAuthOptions.Builder

Sets the callbacks to get the status of phone number verification.

PhoneAuthOptions.Builder

Sets theForceResendingToken to force another verification SMS to be sent before the auto-retrieval timeout.

PhoneAuthOptions.Builder

Sets thePhoneMultiFactorInfo to use for second factor sign-in.

PhoneAuthOptions.Builder

Sets theMultiFactorSession that holds the necessary data to start an SMS verification for multi-factor authentication enrollment or sign in.

PhoneAuthOptions.Builder
setPhoneNumber(phoneNumber: String)

Sets the phone number for sign-in, sign-up, or second factor enrollment.

PhoneAuthOptions.Builder
setTimeout(timeout: Long, unit: TimeUnit)

Sets the maximum amount of time you are willing to wait for SMS auto-retrieval to be completed by the library.

Public constructors

Builder

Builder(auth: FirebaseAuth)

Creates a new Builder

Parameters
auth: FirebaseAuth

theFirebaseAuth with which this Builder is associated.

Public functions

build

fun build(): PhoneAuthOptions

Returns thePhoneAuthOptions that thisBuilder has constructed.

requireSmsValidation

fun requireSmsValidation(requireSmsValidation: Boolean): PhoneAuthOptions.Builder

Specifies whether to force an SMS to be sent for second factor validation.

In some cases the phone number can be instantly verified without needing to send or enter a verification code. This feature can be disabled here, and it is enabled by default.

This is only applicable to Multi-Factor Authentication.

setActivity

fun setActivity(activity: Activity): PhoneAuthOptions.Builder

Sets theActivity to which the callbacks are scoped, and with which app verification will be completed. This is an optional parameter of the builder, but is required to perform a reCAPTCHA fallback for client verification. If the activity is not set and a reCAPTCHA verification is attempted, aFirebaseAuthMissingActivityForRecaptchaException error is thrown, which can be handled in theonVerificationFailed callback.

setCallbacks

fun setCallbacks(
    callbacks: PhoneAuthProvider.OnVerificationStateChangedCallbacks
): PhoneAuthOptions.Builder

Sets the callbacks to get the status of phone number verification. The callbacks will be automatically removed when the specified activity has stopped.

When a test phone number and SMS code pair is set viasetAutoRetrievedSmsCodeForPhoneNumber and in the Firebase console,onCodeAutoRetrievalTimeOut will never be triggered.

setForceResendingToken

fun setForceResendingToken(
    forceResendingToken: PhoneAuthProvider.ForceResendingToken
): PhoneAuthOptions.Builder

Sets theForceResendingToken to force another verification SMS to be sent before the auto-retrieval timeout.

setMultiFactorHint

fun setMultiFactorHint(phoneMultiFactorInfo: PhoneMultiFactorInfo): PhoneAuthOptions.Builder

Sets thePhoneMultiFactorInfo to use for second factor sign-in.

setMultiFactorSession

fun setMultiFactorSession(multiFactorSession: MultiFactorSession): PhoneAuthOptions.Builder

Sets theMultiFactorSession that holds the necessary data to start an SMS verification for multi-factor authentication enrollment or sign in.

When this is set, the verification will be for validating ownership of a phone SMS second factor, not for phone authentication.

setPhoneNumber

fun setPhoneNumber(phoneNumber: String): PhoneAuthOptions.Builder

Sets the phone number for sign-in, sign-up, or second factor enrollment.

Parameters
phoneNumber: String

a phone number that conforms to the E.164 format.

setTimeout

fun setTimeout(timeout: Long, unit: TimeUnit): PhoneAuthOptions.Builder

Sets the maximum amount of time you are willing to wait for SMS auto-retrieval to be completed by the library.

The minimum timeout is 30 seconds, and the maximum timeout is 2 minutes. If you specified a positive value less than 30 seconds, library will default to 30 seconds. Specifying a negative timeout or a timeout that is greater than 120 seconds will result in an being thrown.

Use 0 to disable SMS-auto-retrieval. This will also causeonCodeAutoRetrievalTimeOut to be called immediately.

Parameters
timeout: Long

the length of the timeout in the units specified byunit.

unit: TimeUnit

theTimeUnit for thetimeout.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.