Снова не получаю OTP на тот же зарегистрированный номер с аутентификацией в firebase - PullRequest
1 голос
/ 07 марта 2020

Я использую Firebase аутентификацию телефона в моем приложении Android. Но я не получаю otp после переустановки приложения на том же. Это только отправка уведомлений о новых номерах и после регистрации с новым номером. Если я попытаюсь отправить otp еще раз на тот же номер, то этого не произойдет.

Вот моя стартовая деятельность

@Override
protected  void onStart() {


    super.onStart();

    if(FirebaseAuth.getInstance().getCurrentUser()!=null){

        Intent passIntent = new Intent(this, MainActivity.class);
        passIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(passIntent);




    }


}

Вот мой otpVerification экран активности

    String phoneNumber = getIntent().getStringExtra("UserPhoneNumber");
    sendVerificationCode(phoneNumber);

    // save phone number
    SharedPreferences prefs = getApplicationContext().getSharedPreferences("USER_PREF",
            Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString("UserPhoneNumber", phoneNumber);
    editor.apply();

    buttonSignIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String code = editText.getText().toString().trim();

            if (code.isEmpty() || code.length() < 6) {

                editText.setError("Enter code...");
                editText.requestFocus();
                return;
            }
            verifyCode(code);
        }
    });

}

private void verifyCode(String code) {
    PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);
    signInWithCredential(credential);
}

private void signInWithCredential(PhoneAuthCredential credential) {
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {

                        Intent intent = new Intent(otpVerfication.this, MainActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                        startActivity(intent);

                    } else {
                        Toast.makeText(otpVerfication.this, task.getException().getMessage(), Toast.LENGTH_LONG).show();
                        progressBar.setVisibility(View.GONE);
                    }
                }
            });
}

private void sendVerificationCode(String number) {
    progressBar.setVisibility(View.VISIBLE);
    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            number,        // Phone number to verify
            60,                 // Timeout duration
            TimeUnit.SECONDS,   // Unit of timeout
            this,               // Activity (for callback binding)
            mCallBack
    );        // OnVerificationStateChangedCallbacks


    progressBar.setVisibility(View.VISIBLE);
}

private PhoneAuthProvider.OnVerificationStateChangedCallbacks
        mCallBack = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

    @Override
    public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
        super.onCodeSent(s, forceResendingToken);
        verificationId = s;
    }

    @Override
    public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
        String code = phoneAuthCredential.getSmsCode();
        if (code != null) {
            editText.setText(code);
            verifyCode(code);
        }
    }

    @Override
    public void onVerificationFailed(FirebaseException e) {
        Toast.makeText(otpVerfication.this, e.getMessage(), Toast.LENGTH_LONG).show();
        progressBar.setVisibility(View.GONE);
    }
};[enter image description here][1]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...