16

I am facing something different type of problem. I am using Firebase Mobile number authentication in my App. When I am trying to send OTP to the same mobile number that I am using, the OTP is not sending. However, if I am sending OTP to the other mobiles from my mobile OTP is sending. I also found If I send OTP from another mobile to my number OTP is coming. Hence there is no issue of Mobile Number. On Debugging I found that this code block is not working

@Override
    public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
        super.onCodeSent(verificationId, forceResendingToken);

        Log.e(TAG, "onCodeSent: s - " + verificationId + " : t - " + forceResendingToken);
        xVerificationId = verificationId;
    }

For other numbers, it is working and verification and forceResendingToken are generating.

techtechie
  • 161
  • 1
  • 1
  • 9

10 Answers10

18

If you have added your phone number in testing under firebase(Sign-in method->Phones). then please remove from there to get otp.

Rakesh
  • 522
  • 4
  • 13
  • 2
    It is not always the case. I am having these issues with the OTP where some users are not receiving it but some are. – Ashique Bava Oct 08 '21 at 11:23
6

Are you implementing onVerificationCompleted? In the following 2 cases, no OTP is sent, as explained in https://firebase.google.com/docs/auth/android/phone-auth:

  • Instant verification: phone number can be instantly verified without the need to send an OTP.
  • Auto-retrieval: Google Play Services can automatically detect the OTP without any user action.

In this case, you will directly get back a PhoneAuthCredential.

bojeil
  • 29,642
  • 4
  • 69
  • 76
5

As explained already, The phone number is getting verified automatically either by

  1. Instant Verification or
  2. Auto Retrieval

which is why onCodeSent() isn't working.

Now, In order to get rid of the problem, you will need to implement onVerificationCompleted(), most chances are that you have implemented it already but you don't know what put inside.

if you are inside onVerificationCompleted(), then you may not have the OTP with you but you definitely have phoneAuthCredential, you just need to pass this variable to mAuth.signInWithCredential() and that should lead to you to your desired output.

sample code for :

        @Override
        public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {

            Toast.makeText(getApplicationContext(),"Verifying code Automatically",LENGTH_LONG).show();

            signInWithCredential(phoneAuthCredential);

        }

sample code for :

private void signInWithCredential(PhoneAuthCredential credential) {
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {

                        // Sign in success, update UI with the signed-in user's information
                        // Log.d(TAG, "signInWithCredential:success");


                    } else {
                        // Sign in failed, display a message and update the UI
                        // Log.w(TAG, "signInWithCredential:failure", task.getException());

                        }
                    }
                }
            });
}
Manish Patel
  • 23
  • 1
  • 6
3

Update the SHA1 fingerprint. It worked for me.

2

Worked for me .

Sometimes Google is unable to verify the request coming from you app. In order to solve it. Re-generate your app's signing report and get your SHA-1 or SHA-256 fingerprints. Go to your firebase project setting and add those fingerprints.

How to generate fingerprints

Hritik Gupta
  • 611
  • 5
  • 20
1

In my case, I realized that this problem happens with all numbers that has ported from one provider to another. With phone numbers that has never ported Firebase Authentication works like a charm!

Pravin Desai
  • 527
  • 5
  • 18
0

For me application id was not updated since I changed my package name and generated a new google-services.json.

Updating the 'applicationid' solved the issue!

Kanagalingam
  • 2,096
  • 5
  • 23
  • 40
0

Use the dependency implementation 'androidx.browser:browser:1.2.0' in your build.gradle file. Firebase now wants to check verification through images, This dependency will allow to open the browser and the Captcha will be verified and you will get the OTP.

Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
Abhishek
  • 81
  • 8
0
  1. Update your SHA keys. If your app is in Playstore then you will get new SHA keys from Play Console: release---> app intrigity---> SHAH keys. sometimes they updates their website so it will better to search How to get SHA Keys from play console
  • 1
    Please add further details to expand on your answer, such as working code or documentation citations. – Community Sep 09 '21 at 09:13
0

In my case, the received OTP was in the spam.

for more information visit

Ninad7N
  • 544
  • 4
  • 13