java - 验证失败(Firebase 安卓)
问题描述
我正在尝试通过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 - 如何解决Function1中的Function1(Context)不能应用于()
- c++ - c++:求解非自由方程的动态系统
- python - python AssertionError中的unittest assertionError:
!= 200 - python - n 维矩阵中的矩阵切片问题
- android - 我需要在哪里添加 Toast?
- python - Django Ajax Likes 工作不正确:jQuery 的问题
- python - 如何从下拉菜单中选择
- python - 修复 ValueError:形状 (1,2) 和 (4,4) 未对齐:python 中的 2 (dim 1) != 4 (dim 0)
- javascript - 两个用于滑动相同 div 但方式不同的按钮(从右到左和从左到右)
- excel - 每次我找到搜索结果时为每个 excel 行着色