2

I trying to handle the new permission model in Android version 23 using the library called Dexter:

https://github.com/Karumi/Dexter

Problem is that if i need to check permission access to SYSTEM_ALERT_WINDOW callback onPermissionDenied is always called without the displaying the permission dialog.

PermissionListener dialogPermissionListener = new PermissionListener() {
                @Override public void onPermissionGranted(PermissionGrantedResponse response) {
                    Logger.d("onPermissionGranted");
                }
                @Override public void onPermissionDenied(PermissionDeniedResponse response) {
                    Logger.d("onPermissionDenied");

                }

                @Override public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {
                    Logger.d("onPermissionRationaleShouldBeShown");
                }
            };

            Dexter.checkPermission(dialogPermissionListener, Manifest.permission.SYSTEM_ALERT_WINDOW);

How can i do permission check in the right way?

Note: Permission check is processed in the service, not in the Activity because service should to display SYSTEM_ALERT_WINDOW above the all other windows in the app (is permission is granted).

Many thanks for any advice.

redrom
  • 11,502
  • 31
  • 157
  • 264
  • Have you tried to change the `checkPermission` method to `checkPermissionOnSameThread`? I suspect that you are receiving the callback in a different thread since you are using a Service. Also, this might be useful: http://stackoverflow.com/questions/32292675/how-to-request-permissions-from-a-service-in-android-marshmallow – Renan Bandeira Nov 04 '16 at 08:25

2 Answers2

2

You should also add the permissions in the AndroidManifest.xml

Adam
  • 21
  • 3
2

Permissions SYSTEM_ALERT_WINDOW and WRITE_SETTINGS are considered special by Android. Dexter doesn't handle those and you'll need to request them in the old fashioned way.

[Already mentioned here in the lib itself][1] https://github.com/Karumi/Dexter#caveats

Truly
  • 374
  • 4
  • 4