Eco4ndly
Eco4ndly

Reputation: 515

Firebase phone authentication is working fine in debug mode but the app is crashing in release

Is it because of permissions?

I have granted READ_SMS , RECEIVE_SMS, READ_PHONE_STATE permissions at the run-time but still its crashing.

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) 

What else needed to be done?

UPDATE

in 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 code is huge I'm explaining how it works. When it starts I'm checking for permissions for marshmallow then after all permissions are granted the phone number is taken as input from user and then its going to 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
}

And the verification call back is like this

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();
        }
    };

The app is crashing after showing the the progress bar in verifyPhone(). No code is being sent.

Upvotes: 0

Views: 1506

Answers (4)

Eco4ndly
Eco4ndly

Reputation: 515

Well, the problem has been solved.

My understanding of the problem was wrong. The problem was not because of the Android version. The problem arose for every version.

Reason

As I described that the application was working fine in debug mode but not working in release mode. I used firebase phone authentication. And there SHA certificate fingerprints are needed. Unfortunately, I forgot to provide release SHA-1. I was using debug SHA-1 fingerprint for the release version.

Solution

Provided the release SHA-1 fingerprint.

Upvotes: 2

Shreya Prajapati
Shreya Prajapati

Reputation: 114

Go to settings-> developer options -> Application section & Make sure your 'Do Not keep activities' option is off then try

Upvotes: 0

Omkar
Omkar

Reputation: 3100

IMO you have to pass proper key,value pair to intent.puExtra() try below code

intent.putExtra("result",55);

then your data.getStringExtra("result"); get value

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

OR try below code this may help

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);

for more check this link

Upvotes: 0

Dharmishtha
Dharmishtha

Reputation: 1343

after adding @Omi's answer , here is another one condition which you need to put .

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

Hope this Help.

Upvotes: 0

Related Questions