Firebase手机身份验证在调试模式下运行良好,但应用程序在发布时崩溃

时间:2017-12-26 05:35:07

标签: android firebase-authentication android-permissions

是否因为权限?

我在运行时授予READ_SMS , RECEIVE_SMS, READ_PHONE_STATE权限但仍然崩溃。

12-26 10:56:02.409 30698-30698/? E/UncaughtException: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=55, result=0, data=null} to activity {com.app.eco4ndly.pathshala/com.app.eco4ndly.pathshala.Opening_Screen}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
                                                      at android.app.ActivityThread.deliverResults(ActivityThread.java:4255)
                                                      at android.app.ActivityThread.handleSendResult(ActivityThread.java:4298)
                                                      at android.app.ActivityThread.-wrap20(ActivityThread.java)
                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
                                                      at android.os.Handler.dispatchMessage(Handler.java:110)
                                                      at android.os.Looper.loop(Looper.java:203)
                                                      at android.app.ActivityThread.main(ActivityThread.java:6339)
                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
                                                   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
                                                      at com.app.eco4ndly.pathshala.Opening_Screen.onActivityResult(Opening_Screen.java:108)
                                                      at android.app.Activity.dispatchActivityResult(Activity.java:6948)
                                                      at android.app.ActivityThread.deliverResults(ActivityThread.java:4251)
                                                      at android.app.ActivityThread.handleSendResult(ActivityThread.java:4298) 
                                                      at android.app.ActivityThread.-wrap20(ActivityThread.java) 
                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613) 
                                                      at android.os.Handler.dispatchMessage(Handler.java:110) 
                                                      at android.os.Looper.loop(Looper.java:203) 
                                                      at android.app.ActivityThread.main(ActivityThread.java:6339) 
                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084) 
                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945) 

还有什么需要做的?

更新

Openning_Screen.java

private void attemptsRegistration() {

    Intent intent = new Intent(Opening_Screen.this,PhoneVerification.class);
    intent.putExtra(Constant.REQUEST_CODE,55);
    startActivityForResult(intent,55);
}

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        final View view = findViewById(android.R.id.content);
        if (requestCode == 55){
            String result = data.getStringExtra("result");
            if (result.equals("PhoneVerifiedSuccessfully")){
                RegistrationDataPass.setPhone(data.getStringExtra("phone"));
                Intent i = new Intent(Opening_Screen.this,RegPage1.class);
                i.putExtra("PhoneNumber",data.getStringExtra("phone"));
                startActivity(i);
            }else if (result.equals("InvalidCode")){
                Constant.showSnak(view,"Registration Failed\nInvalid Code");
            }else if (result.equals("INVALID REQUEST")){
                Constant.showSnak(view,"Registration Failed\nINVALID REQUEST");
            }else if (result.equals("Too many Request")){
                Constant.showSnak(view,"Registration Failed\nToo many Requests");
            }
        }
}

Phone_Verification.java代码非常庞大,我解释它是如何工作的。 当它开始我检查 marshmallow 的权限时,在授予所有权限后,电话号码将被视为来自用户的输入,然后转到verifyPhone()

public void verifyPhone(String phn, PhoneAuthProvider.OnVerificationStateChangedCallbacks _mCallbacks){
    mCallbacksResend = _mCallbacks;
    Constant.showProgressBar(this,"You will receive an OTP in "+phn);
    Log.e("STEP Inside ver pn",phn);
    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            phn,        // Phone number to verify
            60,                 // Timeout duration
            TimeUnit.SECONDS,   // Unit of timeout
            this,               // Activity (for callback binding)
            _mCallbacks);        // OnVerificationStateChangedCallback
}

验证回电就像这样

final PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallBacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
        @Override
        public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
            //progressDialog.dismiss();
            Log.d("JEJE", "onVerificationCompleted:" + phoneAuthCredential);
            Log.e("STEP in signin","InsideVerification");
            signInWithPhoneAuthCredential(phoneAuthCredential);
        }

        @Override
        public void onVerificationFailed(FirebaseException e) {
            Constant.hideProgressBar();
            Log.w("JEJE", "onVerificationFailed", e);
            if (e instanceof FirebaseAuthInvalidCredentialsException) {
                Log.d("JEJE", "INVALID REQUEST");
                Intent intent = new Intent();
                intent.putExtra("result","INVALID REQUEST");
                intent.putExtra("phone",phoneNumber);
                setResult(REQ_CODE,intent);
            } else if (e instanceof FirebaseTooManyRequestsException) {
                Log.d("JEJE", "Too many Request");
                Intent intent = new Intent();
                intent.putExtra("result","Too many Request");
                intent.putExtra("phone",phoneNumber);
                setResult(REQ_CODE,intent);
            }
            showSnakBar(e.toString());
            //hideProgressDialog();
            Constant.hideProgressBar();
            Toast.makeText(PhoneVerification.this, "Failed", Toast.LENGTH_SHORT).show();
            finish();
        }
        @Override
        public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
            super.onCodeSent(s, forceResendingToken);
            //hideProgressDialog();
            Constant.hideProgressBar();
            Log.d("JEJE", "onCodeSent:" + s);
            mResendToken = forceResendingToken;
            tv.setText("We have sent a verification Code to your number "+phoneNumber+" via SMS.\nEnter the CODE bellow");
            phoneNumLayout.setVisibility(View.GONE);
            otpLayout.setVisibility(View.VISIBLE);
            verifyToken = s;
            showTimer();
        }
    };

verifyPhone()中显示进度条后,应用程序崩溃了。没有代码被发送。

4 个答案:

答案 0 :(得分:3)

嗯,问题已经解决了

我对这个问题的理解是错误的。问题不在于Android版本。每个版本都会出现问题。

<强>原因

正如我所描述的那样,应用程序在调试模式下工作正常,但在发布模式下无效。我用过firebase手机验证。并且需要SHA certificate fingerprints。不幸的是,我忘了提供发布SHA-1。我在发布版本中使用了调试SHA-1指纹。

<强>解决方案

提供发布SHA-1指纹。

答案 1 :(得分:0)

IMO您必须将key,value对传递给intent.puExtra()尝试以下代码

intent.putExtra("result",55);

然后您的data.getStringExtra("result");获取值

 if (requestCode == 55){
            String result = data.getStringExtra("result");

尝试以下代码可能会有所帮助

Intent intent = new Intent(Opening_Screen.this,PhoneVerification.class);
intent.putExtra(Constant.REQUEST_CODE,55);
intent.putExtra("result",YOUR_RESULT_STRING);
intent.putExtra("phone",PHONE_STRING);
startActivityForResult(intent,55);

了解更多支票this link

答案 2 :(得分:0)

在添加@Omi的答案之后,这是另一个你需要提出的条件。

if (requestCode == 55 && data!=null){
  //here your code
}

希望得到这个帮助。

答案 3 :(得分:0)

转到设置 - &gt;开发者选项 - &gt;申请部分&amp; 确保您的“不要保持活动”#39;选项已关闭然后尝试