Firebase电话身份验证SMS代码null android [英] Firebase Phone Authentication SMS Code null android

查看:58
本文介绍了Firebase电话身份验证SMS代码null android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 firebase 电话身份验证添加到我的android项目中.首先,一切顺利.一段时间后, onVerificationCompleted()中的短信代码为空.谢谢!

I have added firebase phone auth to my android project. First everything goes fine. After sometime, the sms code in onVerificationCompleted() is null.Thanks!!

PhoneAuthProvider.getInstance().verifyPhoneNumber(mobileNumber, 60, TimeUnit.SECONDS, FirebasePhoneAuthActivity.this, new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
    @Override
    public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
        smsCode = phoneAuthCredential.getSmsCode();
        Log.i(TAG, "onVerificationCompleted: CODE " + smsCode);
        Log.i(TAG, "onVerificationCompleted: PROVIDER " + phoneAuthCredential.getProvider());
    }

    @Override
    public void onVerificationFailed(FirebaseException e) {
        e.printStackTrace();
    }

    @Override
    public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
        Log.i(TAG, "onCodeSent: CODE " + s);

    }

    @Override
    public void onCodeAutoRetrievalTimeOut(String s) {
        super.onCodeAutoRetrievalTimeOut(s);
        Log.i(TAG, "onCodeAutoRetrievalTimeOut: " + s);
    }
});

推荐答案

这是即时验证.在官方文档中,它说:

This is Instant Verification. In the official docs, it says:

即时验证:在某些情况下,无需发送或输入验证码即可立即验证电话号码.

Instant verification: in some cases the phone number can be instantly verified without needing to send or enter a verification code.

此外,如果您查看开源的 Android版FirebaseUI

Also, if you look at the open-sourced FirebaseUI for Android, on this line of code it suggests that there is a possibility of verification being a success, while sms code being absent. Such a case would denote Instant Verification. So you can safely continue to use this credential to sign the user in.

这篇关于Firebase电话身份验证SMS代码null android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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