I am using Firebase auth api
to verify user phone number. Currently in my case I have one screen where user put phone number and on second screen otp. As per documentation firebase
automatic retrieve otp and start verification process most of time.
So my question is it already implemented this SMS Retriever API
in Firebase Auth SDK or Should I implement it myself to retrieve SMS and auto fill OTP.
With the SMS Retriever API, you can perform SMS-based user verification in your Android app automatically, without requiring the user to manually type verification codes, and without requiring any extra app permissions.
But via Firebase, we can send an SMS without any cost. Firebase offers 10,000 verifications per month under the free plan.
Nope. we don't need to manage SMS-retrival scenario.
If device contains same SIM-card, It's automatically managed by PhoneAuthProvider.OnVerificationStateChangedCallbacks
in onVerificationCompleted(PhoneAuthCredential phoneAuthCredential)
method.
Snippet:
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(FCMsmsTest.this, "onVerificationCompleted " + phoneAuthCredential.toString(), Toast.LENGTH_SHORT).show();
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(FCMsmsTest.this, "onVerificationFailed " + e.toString(), Toast.LENGTH_SHORT).show();
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(FCMsmsTest.this, "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
Toast.makeText(FCMsmsTest.this, "onCodeSent " + verificationId, Toast.LENGTH_SHORT).show();
editText.setText("");
mVerificationId = verificationId;
PhoneAuthProvider.ForceResendingToken mResendToken = token;
showDialog();
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With