I had registered a user in firebase
using Firebase
phone number authentication
.For testing that functionality again, I deleted the user account from Firebase
console. Now, i am trying to register that number again, its directly going to the onVerificationCompleted()
callback without sending the OTP
.But the user account is not shown in Firebase console.
Please help.
Code given below. Also please note that its sending OTP to the new numbers .But not sending OTP to the number which i deleted from firebase console.I want to register that particular number again.
public class MainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private boolean mVerificationInProgress = false;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
private static final String KEY_VERIFY_IN_PROGRESS = "key_verify_in_progress";
private static final String TAG = "PhoneAuthActivity";
private String mVerificationId;
private PhoneAuthProvider.ForceResendingToken mResendToken;
private EditText mPhoneNumberField;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null) {
onRestoreInstanceState(savedInstanceState);
}
mPhoneNumberField=(EditText)findViewById(R.id.phone_number);
mAuth = FirebaseAuth.getInstance();
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
// This callback will be invoked in two situations:
// 1 - Instant verification. In some cases the phone number can be instantly
// verified without needing to send or enter a verification code.
// 2 - Auto-retrieval. On some devices Google Play services can automatically
// detect the incoming verification SMS and perform verification without
// user action.
Log.d(TAG, "onVerificationCompleted:" + credential);
Toast.makeText(getApplication(),"Verification completed",Toast.LENGTH_SHORT).show();
// [START_EXCLUDE silent]
mVerificationInProgress = false;
Log.d(TAG,"CREDENTIAL"+credential);
// Intent intent=new
Intent(getBaseContext(),VerificationActivity.class);
// intent.putExtra("VERIFICATION_ID",mVerificationId);
// startActivity(intent);
}
@Override
public void onVerificationFailed(FirebaseException e) {
// This callback is invoked in an invalid request for verification is made,
// for instance if the the phone number format is not valid.
Log.w(TAG, "onVerificationFailed", e);
// [START_EXCLUDE silent]
mVerificationInProgress = false;
// [END_EXCLUDE]
if (e instanceof FirebaseAuthInvalidCredentialsException) {
// Invalid request
// [START_EXCLUDE]
mPhoneNumberField.setError("Invalid phone number.");
// [END_EXCLUDE]
} else if (e instanceof FirebaseTooManyRequestsException) {
// The SMS quota for the project has been exceeded
// [START_EXCLUDE]
Snackbar.make(findViewById(android.R.id.content), "Quota exceeded.",
Snackbar.LENGTH_SHORT).show();
// [END_EXCLUDE]
}
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
// The SMS verification code has been sent to the provided phone number, we
// now need to ask the user to enter the code and then construct a credential
// by combining the code with a verification ID.
Log.d(TAG, "onCodeSent:" + verificationId);
// Save verification ID and resending token so we can use them later
mVerificationId = verificationId;
mResendToken = token;
Intent intent=new Intent(getBaseContext(),VerificationActivity.class);
intent.putExtra("VERIFICATION_ID",mVerificationId);
startActivity(intent);
}
};
}
public void verifyDevice(View v){
String phno=mPhoneNumberField.getText().toString();
startPhoneNumberVerification(phno);
}
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
// [END start_phone_auth]
mVerificationInProgress = true;
}
@Override
public void onStart() {
super.onStart();
if (mVerificationInProgress) {
startPhoneNumberVerification(mPhoneNumberField.getText().toString());
}
// [END_EXCLUDE]
}
// [END on_start_check_user]
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_VERIFY_IN_PROGRESS, mVerificationInProgress);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mVerificationInProgress = savedInstanceState.getBoolean(KEY_VERIFY_IN_PROGRESS);
}
Looking forward to some help.
Try to signout of your app or simply clear data or reinstall, it's possible there is a little glitch somewhere within the app.
If the above instruction doesn't work, then the cause is a little deeper. Since the authentication worked the first time, it's most likely a network carrier issue; this happens mostly in cases where a phone number was ported from one network provider to another at some point. You can try experimenting with phone numbers of a different network carrier. Sadly, there is no exact workaround for this problem yet. Whichever case, you can send your complaints to Firebase support. There'd definitely be some help there.