Firebase身份验证是否需要SMS Retriever API才能进行otp自动填充?

Rak*_*esh 5 android firebase android-permissions firebase-authentication

我正在Firebase auth api用来验证用户电话号码。目前,在我的情况下,我有一个屏幕,用户在其中输入电话号码,在第二个屏幕上输入otp。根据文档firebase,大多数时间自动检索otp并开始验证过程。所以我的问题是它是否已SMS Retriever API在Firebase Auth SDK中实现,还是我应该自己实现以检索SMS并自动填充OTP。

Rum*_*tel 4

没有。我们不需要管理短信检索场景。

如果设备包含相同的SIM卡,则由PhoneAuthProvider.OnVerificationStateChangedCallbacksinonVerificationCompleted(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();
        }
    };
Run Code Online (Sandbox Code Playgroud)