如何在 Firebase Phone Authentication Android 中重新发送 SMS 验证? [英] How to resend SMS verification in Firebase Phone Authentication Android?

查看:23
本文介绍了如何在 Firebase Phone Authentication Android 中重新发送 SMS 验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Firebase 文档(https://firebase.google.com/docs/auth/android/phone-auth#send-a-verification-code-to-the-users-phone),有 callback 用于处理电话号码认证.

According to Firebase documentation (https://firebase.google.com/docs/auth/android/phone-auth#send-a-verification-code-to-the-users-phone), there is callback for handling the phone number authentication.

mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

    @Override
    public void onVerificationCompleted(PhoneAuthCredential credential) {

        Log.d(TAG, "onVerificationCompleted:" + credential);
        signInWithPhoneAuthCredential(credential);
    }

    @Override
    public void onVerificationFailed(FirebaseException e) {

        Log.w(TAG, "onVerificationFailed", e);
    }

    @Override
    public void onCodeSent(String verificationId,
                           PhoneAuthProvider.ForceResendingToken token) {

        Log.d(TAG, "onCodeSent:" + verificationId);

        // Save verification ID and resending token so we can use them later
        mVerificationId = verificationId;
        mResendToken = token;
    }
};

我的问题是关于 onCodeSent 方法.它在这里的文档上说(https://firebase.google.com/docs/reference/android/com/google/firebase/auth/PhoneAuthProvider.ForceResendingToken)

My question is on onCodeSent method. It said on the doc here (https://firebase.google.com/docs/reference/android/com/google/firebase/auth/PhoneAuthProvider.ForceResendingToken)

token 可用于强制重新发送短信验证码.然而,在对文档做了一些研究之后,我仍然不知道如何.

that the token can be used to force re-sending an SMS verification code. However, after doing some research on the doc I still don't know how.

请问如何使用这个token重新发送短信验证?

I would like to ask how to use this token to resend the SMS verification ?

推荐答案

来源:Android 版 Firebase 快速入门

这是用于重新发送短信验证的方法.

This is the method used to resend SMS Verifications.

private void resendVerificationCode(String phoneNumber,
                                    PhoneAuthProvider.ForceResendingToken token) {
    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            phoneNumber,        // Phone number to verify
            60,                 // Timeout duration
            TimeUnit.SECONDS,   // Unit of timeout
            this,               // Activity (for callback binding)
            mCallbacks,         // OnVerificationStateChangedCallbacks
            token);             // ForceResendingToken from callbacks
}

这篇关于如何在 Firebase Phone Authentication Android 中重新发送 SMS 验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆