Ошибка аутентификации телефона Firebase на одном устройстве - PullRequest
0 голосов
/ 19 июня 2020

Мое приложение, имеющее метод аутентификации по телефону для регистрации пользователя и входа в firebase, отлично работает на некоторых устройствах, но на одном устройстве оно отправило подтверждающее SMS только в первый раз, когда я его проверил. После этого я даже удалил эту учетную запись из консоли firebase, но она не отправляет код подтверждения при повторной регистрации этого номера.

public class phone_no_verification extends AppCompatActivity {
ProgressBar verify_progress;
    TextInputEditText verify_edittext;
    TextInputLayout verify_textInput;
   String mverificationID;
FirebaseAuth auth;
   static  String TAG;
SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone_no_verification);
        verify_progress = findViewById(R.id.verify_progress);
        verify_edittext = findViewById(R.id.verify_edittext);
        verify_textInput = findViewById(R.id.verify_textinputLayout);



        auth = FirebaseAuth.getInstance();

        //getting Intent mobile number
        Intent intent = getIntent();
        String mobile = intent.getStringExtra("mobile_no");
        sendVerificationcode(mobile);



        //Entering code manually
        findViewById(R.id.verify_Button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String code = verify_edittext.getText().toString().trim();
                if(code.isEmpty() || code.length() < 6){
                    verify_textInput.setError("Enter Valid code");
                }
                else{
                verifyVerificationCode(code);}
            }
        });

    }

    private void sendVerificationcode(String mobile) {
        PhoneAuthProvider.getInstance().verifyPhoneNumber
                ("+91" + mobile,60, TimeUnit.SECONDS,
                        TaskExecutors.MAIN_THREAD,mcallbacks);
    }

    //callback to detect verification status
PhoneAuthProvider.OnVerificationStateChangedCallbacks mcallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
        @Override
        public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
            super.onCodeSent(s, forceResendingToken);
mverificationID = s;
        }

        @Override
        public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
            Log.d(TAG, "onVerificationCompleted:" + phoneAuthCredential);

            String code = phoneAuthCredential.getSmsCode();

if(code != null){
    verify_edittext.setText(code);
    verifyVerificationCode(code);
}
        }

        @Override
        public void onVerificationFailed(@NonNull FirebaseException e) {
            Toast.makeText(phone_no_verification.this, e.getMessage(), Toast.LENGTH_LONG).show();

        }
    };


    private void verifyVerificationCode(String code) {
        PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mverificationID,code);

        //signing user
        signInWithPhoneAuthCredential(credential);
    }

    private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
    auth.signInWithCredential(credential).addOnCompleteListener(phone_no_verification.this
            , new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                  if(task.isSuccessful()){
Intent intent = new Intent(phone_no_verification.this, Basic_activity.class);
                      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

startActivity(intent);
                      sp = getSharedPreferences("login",MODE_PRIVATE);
                      sp.edit().putBoolean("isAutheticated",true).apply();
                  }
                  else{
                      String message = "Somthing is wrong, we will fix it soon...";
                      if(task.getException() instanceof FirebaseAuthInvalidCredentialsException){
                          message = "Invalid code Entered..";
                      }
                      else if(task.getException() instanceof FirebaseAuthUserCollisionException){
                          message = "User Already Exists";
                      }

Toast.makeText(phone_no_verification.this,message,Toast.LENGTH_LONG).show();

                  }


                }
            });

    }
}
...