Karumi / Dexter

Android library that simplifies the process of requesting permissions at runtime.
http://karumi.com
Apache License 2.0
5.23k stars 671 forks source link

Getting below exception when permission is denied second time in fragment #244

Closed lazy-coder-10 closed 4 years ago

lazy-coder-10 commented 4 years ago
 java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=42, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } (has extras) }} to activity {com.shopfeur.user/com.karumi.dexter.DexterActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.finish()' on a null object reference
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4472)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4515)
        at android.app.ActivityThread.-wrap22(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1687)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.finish()' on a null object reference
        at com.karumi.dexter.DexterInstance.onPermissionsChecked(Unknown Source)
        at com.karumi.dexter.DexterInstance.updatePermissionsAsDenied(Unknown Source)
        at com.karumi.dexter.DexterInstance.onPermissionRequestDenied(Unknown Source)
        at com.karumi.dexter.Dexter.onPermissionsRequested(Unknown Source)
        at com.karumi.dexter.DexterActivity.onRequestPermissionsResult(Unknown Source)
        at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7434)
        at android.app.Activity.dispatchActivityResult(Activity.java:7260)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4468)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4515) 
        at android.app.ActivityThread.-wrap22(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1687) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
pedrovgs commented 4 years ago

Hi @rohit6027 could you please provide more information about the error? What's the version of the library you are using when reproducing the error? Can you paste here the piece of code requesting the permission? Could you please list the steps to reproduce the error?

rupinderjeet commented 4 years ago

Hi, I received this too a few moments ago. I am using an AppCompatActivity and I call this code when a button is tapped. Exception stack trace is same as above.

I am using Kotlin with MVVM.

Library: 'com.karumi:dexter:6.0.0' OS: Android Emulator v9.0

Dexter.withActivity(this)
                .withPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
                .withListener(object: BasePermissionListener() {
                    override fun onPermissionGranted(response: PermissionGrantedResponse?) {
                        openProfileImageSelector()
                    }

                    override fun onPermissionDenied(response: PermissionDeniedResponse?) {
                        toast(R.string.error_perm_image_pick)
                    }
                })
                .check()

Reproducing:

  1. Request permission
  2. Deny it
  3. Re-trigger Step 1
  4. Deny
  5. Crash

You might have to do Step 3 & Step 4 about 2 - 4 times.

Is there any quick solution? I rely heavily on Dexter.

pedrovgs commented 4 years ago

Hi @rohit6027 and @rupinderjeet I've sent a tentative fix for this error because even with the steps to reproduce you mentioned we are not able to reproduce the crash. I'd need you to try to reproduce this error in a demo project we can test manually and also to check if the new version we are going to publish as soon as https://github.com/Karumi/Dexter/pull/246 is merged fixes your issue. Please, if the PR I've sent doesn't fix the error, please reopen this issue.

lazy-coder-10 commented 4 years ago

ok I will give you a demo project for this issue asap.

lazy-coder-10 commented 4 years ago

Hi, @pedrovgs I have created a demo project for this exception. Please check it.

Step to produce Exception:-

  1. Permission dialog will be prompted when app launch
  2. deny permission
  3. dialog will be prompted again
  4. deny it again and app will be crashed.

[https://github.com/rohit6027/GlideException.git]

pedrovgs commented 4 years ago

Thank you so much @rohit6027 your project helped me a lot to confirm the latest Dexter release fixed this issue. Update your app to use Dexter 6.0.1 and you won't ever see this error again.