【发布时间】:2020-10-16 06:27:33
【问题描述】:
我正在尝试通过 Firebase 制作一个用于电话号码身份验证的应用。但是我一直收到消息验证失败。 这是OTP认证的代码:-
private void sendVerificationCode(){
String phoneN =phone.getText().toString();
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneN, 60,
TimeUnit.SECONDS,
Registration.this,
mCallbacks);
}
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks= new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(Registration.this,"verification completed",Toast.LENGTH_SHORT).show();
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(Registration.this,"verification failed",Toast.LENGTH_SHORT).show();
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
//super.onCodeSent(s, forceResendingToken);
codeSent=s;
}
};
private void VerifyCode(){
String code= otp.getText().toString();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(codeSent, code);
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()) {
Toast.makeText(getApplicationContext(),"Welcome, You can login now", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Registration.this,Login_Reg.class);
startActivity(intent);
} else {
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
// The verification code entered was invalid
Toast.makeText(getApplicationContext(),"Incorrect Verification Code",Toast.LENGTH_LONG).show();
}
}
}
});
}
}
我不断收到“验证失败”的消息。 下面是用户界面。
如何解决?
【问题讨论】:
标签: java android firebase firebase-authentication