[英]Retrieve SMS code sent to user's phone - Firebase SMS Authentication
[英]Firebase Phone Authentication SMS Code null android
我已將firebase
電話身份驗證添加到我的 android 項目中。 首先一切順利。 一段時間后, onVerificationCompleted()
的短信代碼為空。謝謝!!
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);
}
});
這是即時驗證。 在官方文檔中,它說:
即時驗證:在某些情況下,無需發送或輸入驗證碼即可即時驗證電話號碼。
此外,如果您查看Android的開源FirebaseUI , 在這行代碼上,它表明驗證有可能成功,而 sms 代碼不存在。 這種情況將表示即時驗證。 因此,您可以安全地繼續使用此憑據來登錄用戶。
獲取自動檢索的 SMS 驗證碼(如果適用)。 使用短信驗證時,如果自動檢索成功,您將首先通過 onCodeSent(String, PhoneAuthProvider.ForceResendingToken) 回調,然后使用包含非空短信代碼的 PhoneAuthCredential 回調 onVerificationCompleted(PhoneAuthCredential)。 如果 Firebase 使用其他方法驗證電話號碼並通過 onVerificationCompleted(PhoneAuthCredential) 觸發回調,則 SMS 代碼可以為 null
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.