英文:
Verification failed(Firebase android)
问题
这是关于使用 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,"验证完成",Toast.LENGTH_SHORT).show();
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(Registration.this,"验证失败",Toast.LENGTH_SHORT).show();
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken 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(),"欢迎,现在您可以登录", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Registration.this,Login_Reg.class);
startActivity(intent);
} else {
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
// 输入的验证码无效
Toast.makeText(getApplicationContext(),"验证码不正确",Toast.LENGTH_LONG).show();
}
}
}
});
}
}
我一直收到“验证失败”的消息。以下是用户界面(UI)。
如何解决这个问题?
英文:
I am trying to make an app for phone number authentication through firebase. But I keep getting the message verification failed.
Here is the code for OTP authentication:-
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();
}
}
}
});
}
}
I keep getting the message "verification failed".
Below is the UI.
How to solve this?
答案1
得分: 0
已经找到解决方案...尝试在实际设备上运行。它会起作用的。
英文:
Got the solution...Try to run it on an actual device. It will work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论