根据 Firebase 文档 ( https://firebase.google.com/docs/auth/android/phone-auth#send-a-verification-code-to-the-users-phone ),有用于处理电话号码身份验证的回调
。
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)
token
可用于强制重新发送短信验证码。但是,在对文档进行了一些研究之后,我仍然不知道该怎么做。
请问如何使用token
重发短信验证?
最佳答案
来源:Firebase Quickstarts for Android
这是用于重新发送 SMS 验证的方法。
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
}
关于android - 如何在 Firebase Phone Authentication Android 中重新发送短信验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44688761/