Android app crashes on firebase phone authentication

后端 未结 3 1844
长情又很酷
长情又很酷 2021-01-29 04:25

I am using firebase for phone number authentication.When I used my phone number, it automatically verifies it.But when I use another phone number I get classCastExceptio

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-29 04:37

    I am too late but it worked for me, Use

    mAuth.signInWithCredential(credential)
                .addOnCompleteListener(new OnCompleteListener() {
                    @Override
                    public void onComplete(@NonNull Task task) {
                        if (task.isSuccessful()) {
                            FirebaseUser user = Objects.requireNonNull(task.getResult()).getUser();
                            // handel success
                        } else if (task.isCanceled()){
                           // handel error
                        }
                    }
                });
    

    Instead of using

     mAuth.signInWithCredential(credential)
                    .addOnCompleteListener((Executor) this, new OnCompleteListener() {
                        @Override
                        public void onComplete(@NonNull Task task) {
                            if (task.isSuccessful()) {
                                // Sign in success, update UI with the signed-in user's information
    //                            Log.d(TAG, "signInWithCredential:success");
    //
    //                            FirebaseUser user = task.getResult().getUser();
                                                          } else {
                                // Sign in failed, display a message and update the UI
                                Log.w(TAG, "signInWithCredential:failure", task.getException());
                                if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                                    // The verification code entered was invalid
                                }
                            }
                        }
                    });
    

    I think that (Executer)this context is creating the problem try removing that, not just Executer but any context generates error, I don't know why..

提交回复
热议问题