Reputation: 891
My code:
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
}
@Override
public void onVerificationFailed(FirebaseException e) {
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
otpSent = s;
Log.d("AuthTest", "code sent!");
}
});
Here the phone number is entered in international format (+91 and 10 digits for India). Here, onCodeSent is not called if the user selects a valid phone number of his choice. On the other hand, if I go to Firebase console and enter a phone number for testing, onCodeSent is executed.
I was following a YouTube tutorial here. Many people have asked this developer about the same problem "OTP (i.e, verification code) is not received". Author has not responded.
What's happening here? Has Firebase changed anything or set a limitation on free accounts, or am I missing something?
Upvotes: 0
Views: 2286
Reputation: 891
The issue was of registering the app in the Firebase. Package name and SHA-1 key are needed. This I came to know by intercepting the FirebaseException
at onVerificationFailed
callback as @Tamir Abutbul suggested. Once the app was registered, it started working.
Also, when I tried to run the app from my other Android Studio environment on a different mac, the app registration issue cropped again. This time it told me the SHA-1 key that I entered earlier was not from this mac. So I had to generate another key and add it (you can add multiple keys).
Upvotes: 1