Android app crashes on firebase phone authentication

后端 未结 3 1839
长情又很酷
长情又很酷 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条回答
  • 2021-01-29 04:37

    I am too late but it worked for me, Use

    mAuth.signInWithCredential(credential)
                .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> 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<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> 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..

    0 讨论(0)
  • 2021-01-29 04:41

    In case you don't need a reference to an Activity then replace (Executor) this with the following code:

    new Executor() {
        @Override
        public void execute(Runnable command) {}
    }
    
    0 讨论(0)
  • 2021-01-29 04:47

    I don't know what you're trying to do with this line:

    .addOnCompleteListener((Executor) this, new OnCompleteListener<AuthResult>() {
    

    Casting this to Executor doesn't seem to make sense. What you want instead of this is a reference to the current Activity. Try getActivity() instead to get this reference.

    0 讨论(0)
提交回复
热议问题