I am working on a WhatsApp clone app which am following from a tutorial. Each time I try to click on my Send button to get a verification code from firebase, the app crashes and this is what I get
I have added the SHA1 to firebase and yet I get the same Thing. I have checked all the answers related to this error and yet.
Error Message Here:
Process: com.example.yoo, PID: 23390
java.lang.IllegalArgumentException: Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof, or enrollment ID.
at com.google.android.gms.common.internal.Preconditions.checkArgument(Unknown Source)
at com.google.firebase.auth.PhoneAuthCredential.<init>(com.google.firebase:firebase-auth@@19.3.0:7)
at com.google.firebase.auth.PhoneAuthProvider.getCredential(com.google.firebase:firebase-auth@@19.3.0:36)
at com.example.yoo.view.startup.auth.PhoneLoginActivity.verifyPhoneNumberWithCode(PhoneLoginActivity.java:181)
at com.example.yoo.view.startup.auth.PhoneLoginActivity.access$400(PhoneLoginActivity.java:32)
at com.example.yoo.view.startup.auth.PhoneLoginActivity$1.onClick(PhoneLoginActivity.java:88)
at android.view.View.performClick(View.java:6177)
at android.view.View$PerformClick.run(View.java:23223)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6295)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1094)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
public class PhoneLoginActivity extends AppCompatActivity {
private ActivityPhoneLoginBinding binding;
private String TAG = "PhoneLoginActivity";
private FirebaseAuth mAuth;
private String mVerificationId;
private PhoneAuthProvider.ForceResendingToken mResendToken;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
private ProgressDialog progressDialog;
private FirebaseUser firebaseUser;
private FirebaseFirestore firestore;
// String[] country={"Nigeria","Germany","China","Japan","Israel"};
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_phone_login);
mAuth = FirebaseAuth.getInstance();
firestore = FirebaseFirestore.getInstance();
progressDialog = new ProgressDialog(this);
binding.btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (binding.btnNext.getText().toString().equals("Next")) {
progressDialog.setMessage("Please Wait");
progressDialog.show();
String phone = "+" + binding.edCodeCountry.getText().toString() + binding.edPhone.getText().toString();
startPhoneNumberVerification(phone);
} else {
progressDialog.setMessage("Verifying..");
progressDialog.show();
}
}
});
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
Log.d(TAG, "onVerificationCompleted : Complete");
signInWithPhoneAuthCredential(phoneAuthCredential);
progressDialog.dismiss();
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
Log.d(TAG, "onVerificationFailed :" + e.getMessage());
}
@Override
public void onCodeSent(@NonNull String verificationId,
@NonNull PhoneAuthProvider.ForceResendingToken token) {
Log.d(TAG, "onCodeSent:" + verificationId);
mVerificationId = verificationId;
mResendToken = token;
binding.btnNext.setText("Confirm");
progressDialog.dismiss();
}
};
Continue here
private void startPhoneNumberVerification(String phoneNumber) {
progressDialog.setMessage("Send code to:" + phoneNumber);
progressDialog.show();
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber, 60, TimeUnit.SECONDS, this, mCallbacks
);
}
private void verifyPhoneNumberWithCode(String verificationId, String code) {
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code);
signInWithPhoneAuthCredential(credential);
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
progressDialog.dismiss();
Log.d(TAG, "signInWithCredentials: success");
FirebaseUser user = task.getResult().getUser();
} else {
progressDialog.dismiss();
Log.w(TAG, "signInWithCredential:failure", task.getException());
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
Log.d(TAG, "onComplete : ERROR CODE");
}
}
}
});
}
from Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof,Enrollement ID
No comments:
Post a Comment