【发布时间】:2019-12-07 17:18:23
【问题描述】:
我正在寻找一种方法来查找从 firebase 电话身份验证发送给我的代码,因为我想手动验证该代码。现在问题是 firebase 正在自动检测短信并调用 onVerificationCompleted() 但我有一个按钮,我想手动输入 otp 代码并验证。下面是我的代码。任何帮助将不胜感激。谢谢
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phonenumber,
120,
TimeUnit.SECONDS,
this, new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
Intent intent = new Intent(PhoneVerification.this, PictureActivity.class);
Log.e("iamhere","Credential IS"+phoneAuthCredential);
intent.putExtra("email",email);
intent.putExtra("phoneNumber",phonenumber);
intent.putExtra("password",password);
startActivity(intent);
Toast.makeText(PhoneVerification.this, "Please fill the registration form", Toast.LENGTH_LONG).show();
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
Toast.makeText(PhoneVerification.this, "Failed: "+e.getMessage(), Toast.LENGTH_LONG).show();
}
@Override
public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
Toast.makeText(PhoneVerification.this, "Check your phone for verification code", Toast.LENGTH_LONG).show();
String mVerificationId = s;
}
});
【问题讨论】:
-
我认为这是唯一的验证方法。但是为什么您要手动验证
-
假设我输入了一个手机号码并且该 SIM 卡在另一个手机中,在这种情况下它无法自动验证代码,我必须手动输入该代码
-
您是否可以通过手动输入代码来手动验证它
-
我没有任何字符串代码,我可以检查它是否等于输入的代码
标签: android firebase one-time-password