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

PermissionDeniedResponse.isPermanentlyDenied() always true on Android 6.0 #211

Closed dzboot02 closed 4 years ago

dzboot02 commented 6 years ago

Expected behaviour

When user denies multiple times a permission on Android6.0, he can't use Never ask again checkbox, because it does not exist yet on API23. So using isPermanentlyDenied() has no sense on this API.

Actual behaviour

PermissionDeniedResponse.isPermanentlyDenied() always true

Steps to reproduce

private void requestPermissions() {
      Dexter.withActivity(this)
            .withPermissions(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
            .withListener(new MultiplePermissionsListener() {
               @Override
               public void onPermissionsChecked(MultiplePermissionsReport report) {
                  boolean allDeniedPermanently = true;
                  for (PermissionDeniedResponse deniedResponse : report.getDeniedPermissionResponses()) {
                     if (!deniedResponse.isPermanentlyDenied()) {
                        allDeniedPermanently = false;
                        break;
                     }
                  }

                  if (report.getGrantedPermissionResponses().size() == 0 && allDeniedPermanently) {
                     //all permissions denied permanently
                     //present explanation dialog with go to Settings button
                     return;
                  }
                  if (report.getGrantedPermissionResponses().size() == 0) {
                     //all permissions are denied
                     //present explanation dialog with request again button
                     return;
                  }
                  //at least one permission has been granted
                  startLocalisation();
               }

               @Override
               public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
                  token.continuePermissionRequest();
               }
            }).check();
   }

This code works fine on API 27, but when executed on API 23 it never gets to //all permissions are denied part

Version of the library

I am using this implementation 'com.karumi:dexter:5.0.0'

It would be right to return false in this case to avoid some extra complicated code. And also because will be always represented with the system's Grant Deny dialog if the feature is requested again from the app.

Thank you.

Serchinastico commented 5 years ago

Hi @hiddeneyes02

I see, we are directly associating !ActivityCompat.shouldShowRequestPermissionRationale(activity, permission) to the isPermanentlyDenied flag but as you said, before API 23, it doesn't make much sense and should be false instead. We should be adding that the isPermanentlyDenied method to AndroidPermissionService and check for the Android version there.

I'm sending a PR to fix this issue.