Firebase Phone Verification verifyPhoneNumber() deprecated + Application Crashed

This is what I did to remove the Error:

I referred firebase phone auth documentation and made the necessary changes:

Replace this:

PhoneAuthProvider.getInstance().verifyPhoneNumber(
            phoneNumber, //phone number to be verified
            60, // validity of the OTP
            TimeUnit.SECONDS,
            (Activity) TaskExecutors.MAIN_THREAD,
            mCallBack // onVerificationStateChangedCallback
    );

With this

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(mCallBack)          // OnVerificationStateChangedCallbacks
                    .build();
    PhoneAuthProvider.verifyPhoneNumber(options);

Also, add this to your app/gradle file dependencies:

implementation 'androidx.browser:browser:1.2.0'

This will help firebase to open the browser for reCAPTCHA verification.

Hope this works!


In new Firebase auth version,they've made major changes like Recaptcha for human verification.it needs browser to verify so,Add below depen.and read about changes refer me

 implementation 'androidx.browser:browser:1.2.0'

Finally, I got solutions with the help of Alex Mamo's Answer and This Documentation

The steps which I followed:

  1. Update new dependency implementation 'com.google.firebase:firebase-auth:20.0.0'

  2. Update new code:

    For send OTP:

    PhoneAuthProvider.verifyPhoneNumber(
         PhoneAuthOptions
                 .newBuilder(FirebaseAuth.getInstance())
                 .setActivity(this)
                 .setPhoneNumber(phoneNumber)
                 .setTimeout(60L, TimeUnit.SECONDS)
                 .setCallbacks(mCallbacks)
                 .build());
    

    For Resend OTP

    PhoneAuthProvider.verifyPhoneNumber(
             PhoneAuthOptions
                     .newBuilder(FirebaseAuth.getInstance())
                     .setActivity(this)
                     .setPhoneNumber(phoneNumber)
                     .setTimeout(60L, TimeUnit.SECONDS)
                     .setCallbacks(mCallbacks)
                     .setForceResendingToken(token)
                     .build());
    

    Still, you will get an error as below:

[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17028 A safety_net_token was passed, but no matching SHA-256 was registered in the Firebase console. Please make sure that this application’s packageName/SHA256 pair is registered in the Firebase Console.

  1. You need to copy SHA-256 from your Keystore or JKS file and add here in SHA Certificate fingerprints:

    enter image description here

  2. Finally, You did it.

    There is no need for a reCAPTCHA verification.

Thank you.