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
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..
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) {}
}
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.