如何在Firebase电话认证Android中重新发送短信验证? [英] How to resend SMS verification in Firebase Phone Authentication Android?
问题描述
callback
来处理电话号码身份验证。 mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks (){
@Override
public void onVerificationCompleted(PhoneAuthCredential credential){
Log.d(TAG,onVerificationCompleted:+ credential);
signInWithPhoneAuthCredential(凭证);
$ b $ @覆盖
public void onVerificationFailed(FirebaseException e){
Log.w(TAG,onVerificationFailed,e);
$ b @Override
public void onCodeSent(String verificationId,
PhoneAuthProvider.ForceResendingToken token){
Log.d(TAG, onCodeSent:+ verificationId);
//保存验证ID并重新发送令牌,以便日后使用
mVerificationId = verificationId;
mResendToken = token;
}
};
我的问题在 onCodeSent
方法上。它在这里对文档说( https:/ /firebase.google.com/docs/reference/android/com/google/firebase/auth/PhoneAuthProvider.ForceResendingToken )
即令牌
可用于强制重新发送短信验证码。但是,在对文档进行一些研究之后,我仍然不知道如何。
我想问一下如何使用这个标记
消息来源: Github
这是用来重发短讯验证的方法。
私人void resendVerificationCode(String phoneNumber,
PhoneAuthProvider.ForceResendingToken token){
PhoneAuthProvider.getInstance()。verifyPhoneNumber(
phoneNumber,//电话号码验证
60,//超时时间
TimeUnit.SECONDS,//超时单位
this,// Activity(用于回调绑定)
mCallb ack,// OnVerificationStateChangedCallbacks
token); //从回调中得到ForceResendingToken
$ $ $ $ $ $ $ $ $ $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;
}
};
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)
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.
I would like to ask how to use this token
to resend the SMS verification ?
解决方案 Source: Github
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电话认证Android中重新发送短信验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!