I am really new to android firebase and I have implemented the necessary libraries for Firebase Auth. I try putting a valid number, but the log says its:
W/JEJE: onVerificationFailed
com.google.firebase.FirebaseException: An internal error has occurred. [ INVALID_APP_CREDENTIAL:App validation failed ]
at com.google.android.gms.internal.nf.zzK(Unknown Source)
at com.google.android.gms.internal.og.zza(Unknown Source)
at com.google.android.gms.internal.oh.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Here is my code:
public class MainActivity extends AppCompatActivity {
private static String mVerificationId;
private static PhoneAuthProvider.ForceResendingToken mResendToken;
private static FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editText = (EditText) findViewById(R.id.phone);
Button submit = (Button) findViewById(R.id.submit);
final PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallBacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Log.d("JEJE", "onVerificationCompleted:" + phoneAuthCredential);
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Log.w("JEJE", "onVerificationFailed", e);
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Log.d("JEJE", "INVALID REQUEST");
} else if (e instanceof FirebaseTooManyRequestsException) {
Log.d("JEJE", "Too many Request");
}
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
Log.d("JEJE", "onCodeSent:" + s);
mVerificationId = s;
mResendToken = forceResendingToken;
}
};
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phoneNum = editText.getText().toString();
Toast.makeText(MainActivity.this, phoneNum, Toast.LENGTH_SHORT).show();
verifyPhone(phoneNum,mCallBacks);
}
});
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential phoneAuthCredential) {
mAuth.signInWithCredential(phoneAuthCredential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
FirebaseUser user = task.getResult().getUser();
}else {
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
// The verification code entered was invalid
}
}
}
});
}
public void verifyPhone(String phoneNumber, PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks){
PhoneAuthProvider.getInstance().verifyPhoneNumber(
"+639952874699", // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallback
}
}
please tell me whats wrong thanks..
Adding SHA Certificate Fingerprint solves my problem. Well, Im fairly new to this but I managed to show output and I was able to received a sms verification.
For reference here are my codes: https://github.com/coozgan/TestingPhoneAuth
Well after a while I'll just summarize all I found out about the phone verification. There are a few things you need to do and should remember for it to work.
These are the list of things you need to do in order for it to work:
compile 'com.google.firebase:firebase-auth:11.0.4'
.Authentication
on the menu. Then go to Sign-in Method
and make sure to enable the phone provider. keytool -exportcert -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore
as mentioned in the firebase guide for it. Notice this command is on line so run it all together, and what it will do is it will look for your debug.keystore file on your user in a hidden folder called .android. The default alias for the keystore is androiddebugkey
so dont change it and the default password for it is android
, So when it asks you for a password just use "android".
Then youll see a list of returns and one of them is Sha-1. Put it in your project.
Also notice, this is written of the 16th of august 2017, you cannot do the phone verification on an emulator, so use a real device.
Hope it helps.
Thanks saurabh Yadav for the missing slash ;) apperently I have to put 2 slashes here in order for it to show.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With