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

问题描述 投票:0回答:4

是因为权限吗?

我在运行时授予了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) 

还有什么需要做的?

UPDATE

在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()中显示进度条后,应用程序崩溃了。没有代码被发送。

android firebase-authentication android-permissions
4个回答
3
投票

好吧,问题已经解决了。

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

原因

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

提供了发布SHA-1指纹。


0
投票

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

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

希望这个帮助。


0
投票

IMO你必须通过适当的key,valueintent.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


0
投票

转到设置 - >开发人员选项 - >应用程序部分并确保关闭“不要保留活动”选项然后尝试

© www.soinside.com 2019 - 2024. All rights reserved.