diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java b/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java index 6f3c71c35..14058ac4d 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/java/PhoneAuthActivity.java @@ -18,6 +18,7 @@ import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException; import com.google.firebase.auth.FirebaseUser; import com.google.firebase.auth.PhoneAuthCredential; +import com.google.firebase.auth.PhoneAuthOptions; import com.google.firebase.auth.PhoneAuthProvider; import com.google.firebase.quickstart.auth.R; import com.google.firebase.quickstart.auth.databinding.ActivityPhoneAuthBinding; @@ -175,12 +176,14 @@ protected void onRestoreInstanceState(Bundle savedInstanceState) { private void startPhoneNumberVerification(String phoneNumber) { // [START start_phone_auth] - PhoneAuthProvider.getInstance().verifyPhoneNumber( - phoneNumber, // Phone number to verify - 60, // Timeout duration - TimeUnit.SECONDS, // Unit of timeout - this, // Activity (for callback binding) - mCallbacks); // OnVerificationStateChangedCallbacks + PhoneAuthOptions options = + PhoneAuthOptions.newBuilder(mAuth) + .setPhoneNumber(phoneNumber) // Phone number to verify + .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit + .setActivity(this) // Activity (for callback binding) + .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks + .build(); + PhoneAuthProvider.verifyPhoneNumber(options); // [END start_phone_auth] mVerificationInProgress = true; @@ -196,13 +199,15 @@ private void verifyPhoneNumberWithCode(String verificationId, String code) { // [START resend_verification] private void resendVerificationCode(String phoneNumber, PhoneAuthProvider.ForceResendingToken token) { - PhoneAuthProvider.getInstance().verifyPhoneNumber( - phoneNumber, // Phone number to verify - 60, // Timeout duration - TimeUnit.SECONDS, // Unit of timeout - this, // Activity (for callback binding) - mCallbacks, // OnVerificationStateChangedCallbacks - token); // ForceResendingToken from callbacks + PhoneAuthOptions options = + PhoneAuthOptions.newBuilder(mAuth) + .setPhoneNumber(phoneNumber) // Phone number to verify + .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit + .setActivity(this) // Activity (for callback binding) + .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks + .setForceResendingToken(token) // ForceResendingToken from callbacks + .build(); + PhoneAuthProvider.verifyPhoneNumber(options); } // [END resend_verification] diff --git a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt index 79d3fab73..818f1b709 100644 --- a/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt +++ b/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/PhoneAuthActivity.kt @@ -12,6 +12,7 @@ import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException import com.google.firebase.auth.FirebaseUser import com.google.firebase.auth.PhoneAuthCredential +import com.google.firebase.auth.PhoneAuthOptions import com.google.firebase.auth.PhoneAuthProvider import com.google.firebase.auth.ktx.auth import com.google.firebase.ktx.Firebase @@ -151,12 +152,13 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { private fun startPhoneNumberVerification(phoneNumber: String) { // [START start_phone_auth] - PhoneAuthProvider.getInstance().verifyPhoneNumber( - phoneNumber, // Phone number to verify - 60, // Timeout duration - TimeUnit.SECONDS, // Unit of timeout - this, // Activity (for callback binding) - callbacks) // OnVerificationStateChangedCallbacks + val options = PhoneAuthOptions.newBuilder(auth) + .setPhoneNumber(phoneNumber) // Phone number to verify + .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit + .setActivity(this) // Activity (for callback binding) + .setCallbacks(callbacks) // OnVerificationStateChangedCallbacks + .build() + PhoneAuthProvider.verifyPhoneNumber(options) // [END start_phone_auth] verificationInProgress = true @@ -174,13 +176,15 @@ class PhoneAuthActivity : AppCompatActivity(), View.OnClickListener { phoneNumber: String, token: PhoneAuthProvider.ForceResendingToken? ) { - PhoneAuthProvider.getInstance().verifyPhoneNumber( - phoneNumber, // Phone number to verify - 60, // Timeout duration - TimeUnit.SECONDS, // Unit of timeout - this, // Activity (for callback binding) - callbacks, // OnVerificationStateChangedCallbacks - token) // ForceResendingToken from callbacks + val optionsBuilder = PhoneAuthOptions.newBuilder(auth) + .setPhoneNumber(phoneNumber) // Phone number to verify + .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit + .setActivity(this) // Activity (for callback binding) + .setCallbacks(callbacks) // OnVerificationStateChangedCallbacks + if (token != null) { + optionsBuilder.setForceResendingToken(token) // callback's ForceResendingToken + } + PhoneAuthProvider.verifyPhoneNumber(optionsBuilder.build()) } // [END resend_verification]