Firebase SMS验证/身份验证在某些设备上不起作用

时间:2019-04-30 05:09:05

标签: android firebase firebase-authentication

我正在使用Firebase SMS验证进行身份验证。该代码在大多数设备上都能正常工作,但在 OPPO A37fw 上显示'com.google.firebase.auth.FirebaseAuthException'

这是我的代码,可以在包括其他Oppo设备在内的所有设备上正常工作。仅在OPPO A37fw上显示此错误。

 PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks
        = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
    @Override
    public void onVerificationCompleted(PhoneAuthCredential credential) {
        Log.d(TAG, "onVerificationCompleted:" + credential);
        MobileVerification.credential = credential;
        openOTPvalidation(ON_VERIFICATION);
    }

    @Override
    public void onVerificationFailed(FirebaseException e) {
        postException(context, TAG, e);
    }

    @Override
    public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken token) {
        super.onCodeSent(s, token);
        verificationCode    = s;
        forceResendingToken = token;
        openOTPvalidation(OTP_SEND);
    }
};

private void getOTP() {
    if (activity != null) {
        pDialog = SupportingMethods.showDialogLoading(activity);
        pDialog.show();
    }
    String mobile   = "+91" + mob;
    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            mobile,        // Phone number to verify
            60,                 // Timeout duration
            TimeUnit.SECONDS,   // Unit of timeout
            activity,               // Activity (for callback binding)
            callbacks);        // OnVerificationStateChangedCallbacks
}

Logcat显示:

   com.google.firebase.auth.FirebaseAuthException: This app is not authorized to use Firebase Authentication. Please verifythat the correct package name and SHA-1 are configured in the Firebase Console. [ App validation failed ] 
        at com.google.firebase.auth.api.internal.zzdr.zzb(Unknown Source) 
        at com.google.firebase.auth.api.internal.zzet.zza(Unknown Source) 
        at com.google.firebase.auth.api.internal.zzew.run(Unknown Source) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:160) 
        at android.app.ActivityThread.main(ActivityThread.java:5541) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759) 
        ************ DEVICE INFORMATION *********** 
        Brand: OPPO 
        Device: A37f 
        Model: A37fw 
        Id: LMY47V 
        Product: A37fw

1 个答案:

答案 0 :(得分:0)

如果您已在android助手的帮助下连接了Firebase,则可能会出现此类问题。因此,您需要从firbase控制台下载google-services.json文件的新副本,并将其添加到您的项目文件夹中。这可能会对您有所帮助。