android - otp 自动填充的 Firebase 身份验证是否需要 SMS Retriever API?
问题描述
我正在使用Firebase auth api
验证用户电话号码。目前在我的情况下,我有一个屏幕,用户输入电话号码和第二个屏幕 otp。根据文档firebase
自动检索 otp 并大部分时间开始验证过程。所以我的问题是它已经SMS Retriever API
在 Firebase Auth SDK 中实现了这个,或者我应该自己实现它来检索 SMS 并自动填充 OTP。
解决方案
没有。我们不需要管理短信检索场景。
如果设备包含相同的 SIM 卡,则由PhoneAuthProvider.OnVerificationStateChangedCallbacks
inonVerificationCompleted(PhoneAuthCredential phoneAuthCredential)
方法自动管理。
片段:
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Toast.makeText(FCMsmsTest.this, "onVerificationCompleted " + phoneAuthCredential.toString(), Toast.LENGTH_SHORT).show();
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Toast.makeText(FCMsmsTest.this, "onVerificationFailed " + e.toString(), Toast.LENGTH_SHORT).show();
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Toast.makeText(FCMsmsTest.this, "Invalid Request " + e.toString(), Toast.LENGTH_SHORT).show();
} else if (e instanceof FirebaseTooManyRequestsException) {
Toast.makeText(FCMsmsTest.this, "The SMS quota for the project has been exceeded " + e.toString(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token) {
Toast.makeText(FCMsmsTest.this, "onCodeSent " + verificationId, Toast.LENGTH_SHORT).show();
editText.setText("");
mVerificationId = verificationId;
PhoneAuthProvider.ForceResendingToken mResendToken = token;
showDialog();
}
};
推荐阅读
- python - 有没有正确的方法可以使这段代码工作?
- go - 如何将字符串转换为结构数组
- java - 无法访问集合下的文档
- python - 在行中的特定范围内应用函数
- amazon-web-services - 如何访问 beanstalk 应用程序 venv?
- python-3.x - 无法访问包含 openpyxl 中的公式的单元格
- visual-studio-code - cmake -H 为 CMake 项目生成构建文件?
- reactjs - 我可以在前端应用程序启动(单独部署)时“唤醒”Heroku 服务器吗?
- google-chrome - 带有数字的 Chrome 控制台反斜杠
- flutter - shrinkWrap 在 ListView.builder 中做了什么?