为什么Firebase手机身份验证无法自动签名



我正在实现Firebase Auth模块,以便在我的应用程序中启用电话验证。我根据文档设置了一切,一切正常(我收到短信(。但是;"自动登录"不起作用。android日志显示:

W/FirebaseAuth: [SmsRetrieverHelper] Timed out waiting for SMS.
I/PhoneAuthProvider: Sms auto retrieval timed-out.

这里是进行电话验证的方法verificationPassed()

private void verificationPassed()
{
_otpButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
_phone = _otpUserNumber.getText().toString();
_userName = _otpPassengerName.getText().toString();
if(_phone.length() != 13)
{
FancyToast.makeText(AuthActivity.this, "Wrong number", FancyToast.LENGTH_SHORT, FancyToast.ERROR, false).show();
}
else
{
_otpButton.setVisibility(View.INVISIBLE);
_progressBar.setVisibility(View.VISIBLE);
PhoneAuthOptions options =
PhoneAuthOptions.newBuilder(_firebaseAuth)
.setPhoneNumber(_phone)
.setTimeout(60L, TimeUnit.SECONDS)
.setActivity(AuthActivity.this)
.setCallbacks(_callbacks)
.build();
PhoneAuthProvider.verifyPhoneNumber(options);
}
}
});
_callbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks()
{
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential)
{
String code = phoneAuthCredential.getSmsCode();
Log.d(TAG, "onVerificationCompleted:" + phoneAuthCredential);

if(code != null)
{
_otpNumberText.setOTP(code);
_otpButton.setVisibility(View.INVISIBLE);
_progressBar.setVisibility(View.VISIBLE);
signInWithPhoneAuthCredential(phoneAuthCredential);
}
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e)
{
Log.w(TAG, Objects.requireNonNull(e.getMessage()));
if(e.getMessage().contains("We have blocked all requests from this device due to unusual activity. Try again later"))
{
FancyToast.makeText(AuthActivity.this, "Device blocked due to unusual activity. try again later", FancyToast.LENGTH_SHORT, FancyToast.ERROR, false).show();
}
else if(e.getMessage().contains("A network error (such as timeout, interrupted connection or unreachable host) has occurred"))
{
FancyToast.makeText(AuthActivity.this, "Network Error!", FancyToast.LENGTH_SHORT, FancyToast.ERROR, false).show();
}
else
{
FancyToast.makeText(AuthActivity.this, "Verification failed. Try again", FancyToast.LENGTH_SHORT, FancyToast.ERROR, false).show();
}
_progressBar.setVisibility(View.INVISIBLE);
_otpButton.setVisibility(View.VISIBLE);
}
@Override
public void onCodeSent(@NonNull final String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken)
{
super.onCodeSent(s, forceResendingToken);
_progressBar.setVisibility(View.INVISIBLE);
_otpButton.setVisibility(View.VISIBLE);
_otpUserNumber.setText(_phone);
if(_otpNumberText.getVisibility() == View.VISIBLE && _otpNumber != null)
{
_otpButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if(_otpNumber.isEmpty())
{
FancyToast.makeText(AuthActivity.this, "Enter sent code", FancyToast.LENGTH_SHORT, FancyToast.INFO, false).show();
}
else
{
_otpButton.setVisibility(View.INVISIBLE);
_progressBar.setVisibility(View.VISIBLE);
PhoneAuthCredential _credential = PhoneAuthProvider.getCredential(s, _otpNumber);
signInWithPhoneAuthCredential(_credential);
}
}
});
}
}
};
}

检查您提供的是否为正确的SHA密钥

最新更新