android - Firebase 不发送 OTP

标签 android firebase authentication firebase-authentication one-time-password

我在 firebase 中注册了一个用户使用 Firebase电话号码authentication .为了再次测试该功能,我从 Firebase 中删除了用户帐户。安慰。现在,我正在尝试再次注册该号码,它直接转到 onVerificationCompleted()不发送 OTP 的回调.但用户帐户未显示在 Firebase 控制台中。

请帮忙。

下面给出的代码。另请注意,它会将 OTP 发送到新号码。但不会将 OTP 发送到我从 Firebase 控制台中删除的号码。我想再次注册该特定号码。

public class MainActivity extends AppCompatActivity {

private FirebaseAuth mAuth;

private boolean mVerificationInProgress = false;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;

private static final String KEY_VERIFY_IN_PROGRESS = "key_verify_in_progress";

private static final String TAG = "PhoneAuthActivity";
private String mVerificationId;
private PhoneAuthProvider.ForceResendingToken mResendToken;

private EditText mPhoneNumberField;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState != null) {
        onRestoreInstanceState(savedInstanceState);
    }

    mPhoneNumberField=(EditText)findViewById(R.id.phone_number);

    mAuth = FirebaseAuth.getInstance();

    mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

        @Override
        public void onVerificationCompleted(PhoneAuthCredential credential) {
            // This callback will be invoked in two situations:
            // 1 - Instant verification. In some cases the phone number can be instantly
            //     verified without needing to send or enter a verification code.
            // 2 - Auto-retrieval. On some devices Google Play services can automatically
            //     detect the incoming verification SMS and perform verification without
            //     user action.
            Log.d(TAG, "onVerificationCompleted:" + credential);
            Toast.makeText(getApplication(),"Verification completed",Toast.LENGTH_SHORT).show();
            // [START_EXCLUDE silent]
            mVerificationInProgress = false;

            Log.d(TAG,"CREDENTIAL"+credential);

//                Intent intent=new 
Intent(getBaseContext(),VerificationActivity.class);
//                intent.putExtra("VERIFICATION_ID",mVerificationId);
//                startActivity(intent);


        }




        @Override
        public void onVerificationFailed(FirebaseException e) {
            // This callback is invoked in an invalid request for verification is made,
            // for instance if the the phone number format is not valid.
            Log.w(TAG, "onVerificationFailed", e);
            // [START_EXCLUDE silent]
            mVerificationInProgress = false;
            // [END_EXCLUDE]

            if (e instanceof FirebaseAuthInvalidCredentialsException) {
                // Invalid request
                // [START_EXCLUDE]
                mPhoneNumberField.setError("Invalid phone number.");
                // [END_EXCLUDE]
            } else if (e instanceof FirebaseTooManyRequestsException) {
                // The SMS quota for the project has been exceeded
                // [START_EXCLUDE]
                Snackbar.make(findViewById(android.R.id.content), "Quota exceeded.",
                        Snackbar.LENGTH_SHORT).show();
                // [END_EXCLUDE]
            }


        }

        @Override
        public void onCodeSent(String verificationId,
                               PhoneAuthProvider.ForceResendingToken token) {
            // The SMS verification code has been sent to the provided phone number, we
            // now need to ask the user to enter the code and then construct a credential
            // by combining the code with a verification ID.
            Log.d(TAG, "onCodeSent:" + verificationId);

            // Save verification ID and resending token so we can use them later
            mVerificationId = verificationId;
            mResendToken = token;

            Intent intent=new Intent(getBaseContext(),VerificationActivity.class);
            intent.putExtra("VERIFICATION_ID",mVerificationId);
            startActivity(intent);


        }
    };
}


public void verifyDevice(View v){

    String phno=mPhoneNumberField.getText().toString();
    startPhoneNumberVerification(phno);


}

private void startPhoneNumberVerification(String phoneNumber) {
    // [START start_phone_auth]
    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            phoneNumber,        // Phone number to verify
            60,                 // Timeout duration
            TimeUnit.SECONDS,   // Unit of timeout
            this,               // Activity (for callback binding)
            mCallbacks);        // OnVerificationStateChangedCallbacks
    // [END start_phone_auth]

    mVerificationInProgress = true;


}


@Override
public void onStart() {
    super.onStart();

    if (mVerificationInProgress) {
        startPhoneNumberVerification(mPhoneNumberField.getText().toString());
    }
    // [END_EXCLUDE]
}
// [END on_start_check_user]

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBoolean(KEY_VERIFY_IN_PROGRESS, mVerificationInProgress);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mVerificationInProgress = savedInstanceState.getBoolean(KEY_VERIFY_IN_PROGRESS);
}

期待一些帮助。

最佳答案

尝试退出您的应用程序或简单地清除数据或重新安装,应用程序内的某处可能存在小故障。

如果上面的指令不起作用,那么原因就更深了。由于身份验证第一次工作,这很可能是网络运营商的问题;这主要发生在电话号码在某个时候从一个网络提供商转移到另一个网络提供商的情况下。您可以尝试使用不同网络运营商的电话号码。 可悲的是,目前还没有针对此问题的确切解决方法。 无论哪种情况,您都可以将您的投诉发送至 Firebase support .那里肯定会有一些帮助。

关于android - Firebase 不发送 OTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48536142/

相关文章:

android - 如何在 Xamarin.Forms 中获取 iOS 和 Android 的辅助功能字体大小,以便我可以在 HTML WebView 中更改字体大小?

Angular 12 : Firebase modulesnot correctly provided (? )

ios - 如何将移动联系人列表与 Firebase 注册联系人列表相匹配并且那些匹配联系人如何从两个列表中获取常用联系人

authentication - 如何为 JWT token 生命周期验证添加额外检查?

node.js - 在strongloop上创建新用户,无需输入电子邮件

java - 不同 ListView 项的不同选择颜色

android - 更改切换按钮的颜色

android - 滚动时工具栏折叠不起作用

javascript - firestore 数据结构的最佳实践是什么?

authentication - 如何在布局中访问登录的用户数据。 (蛋糕PHP 3)