当我卸载并重新安装android应用程序时,验证码和消息越来越完美,但是当我重新启动应用程序并发送手机号码进行验证时,我没有收到任何消息或验证码。重发按钮上也有同样的事情。
我没有收到任何错误消息。
我的代码是....
private void sendVerificationCode(String mobile) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
mobile,
60,
TimeUnit.SECONDS,
TaskExecutors.MAIN_THREAD,
mCallbacks);
}
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks =
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential
phoneAuthCredential) {
String code = phoneAuthCredential.getSmsCode();
Log.i("sad","codeis========"+code);
if (code != null) {
edtphoneemail.setText(code);
verifyVerificationCode(code);
}
}
@Override
public void onVerificationFailed(FirebaseException e) {
//Toast.makeText(VerifyPhoneActivity.this, e.getMessage(),
Toast.LENGTH_LONG).show();
Log.i("a","asdf==="+e);
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken
forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
Log.i("sadf","sdf=====code sucess fiully"+s);
//storing the verification id that is sent to the user
mVerificationId = s;
mResendToken = forceResendingToken;
}
};
private void verifyVerificationCode(String code) {
//creating the credential
PhoneAuthCredential credential =
PhoneAuthProvider.getCredential(mVerificationId, code);
Log.i("sdf","mVerificationId===="+code);
//signing the user
signInWithPhoneAuthCredential(credential);
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential)
{
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>
() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.i("sadf","sdf=====code sucess fiully");
} else {
String message = "Somthing is wrong, we will fix it
soon...";
if (task.getException() instanceof
FirebaseAuthInvalidCredentialsException) {
message = "Invalid code entered...";
}
Snackbar snackbar =
Snackbar.make(findViewById(R.id.parent), message,
Snackbar.LENGTH_LONG);
snackbar.setAction("Dismiss", new
View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
snackbar.show();
}
}
});
}
private void resendVerificationCode(String phoneNumber,
PhoneAuthProvider.ForceResendingToken token) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks, // OnVerificationStateChangedCallbacks
token); // ForceResendingToken from callbacks
}
答案 0 :(得分:2)
您不会每次都获得OTP。 Firebase会自动检测手机中的SIM卡以及与其关联的电话号码。如果成功,则身份验证将自动完成,您必须登录用户。
答案 1 :(得分:0)
我只是将SIM卡网络类型从4g更改为2g,然后从Firebase获取了OTP