我正在使用使用Firebase的电话身份验证将SMS发送到电话号码。它正在发送带有生成数字的短信,但是当执行OnCodeSent时,返回的字符串为null,因为onVerificationCompleted也未执行,所以它也不会自动验证。
public static void sendVerificationCode(final Activity activity, final String mobileNumber)
{
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
CommonMethods.createToast(activity.getApplicationContext(), "Verified");
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
CommonMethods.createToast(activity.getApplicationContext(), "Something went wrong, please make sure" +
" that you enter '+' before your country code");
}
@Override
public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
Log.i("verificationcode", s);
Intent goToVerificationIntent = new Intent(activity, VerificationActivity.class);
goToVerificationIntent.putExtra("codeSent", s);
goToVerificationIntent.putExtra("mobileNumber", mobileNumber);
activity.startActivity(goToVerificationIntent);
activity.finish();
}
};
PhoneAuthProvider.getInstance().verifyPhoneNumber(
mobileNumber,
60,
TimeUnit.SECONDS,
activity,
mCallbacks);
}