How to request permissions from a Service in Android Marshmallow How to request permissions from a Service in Android Marshmallow android android

How to request permissions from a Service in Android Marshmallow


requestPermission() can only be called from an Activity and not a Service (unlike checkPermission() that only requires PackageManager). So you need to do some extra work to get around that; you do need to provide an Activity in your app and, for example, your Service can check for permissions it needs and if they have not been granted yet, it can create a notification and that can inform user with a descriptive short message as to why there is a notification and what needs to happen when they click on the notification, etc.


I agree, this is very troublesome for services, I think you should report an issue on Android Developer Preview page for this.

At the moment, I think the best solution is to check for permission on service, and show notification if the permission is missing. Even better, create an DialogActivity to request for permission when users press on the notification.


Have a look at PermissionEverywhere library. It allows you to request permission from any context.

It creates a notification clicking on which it opens up an activity asking for permission.

Sample code from library's github page:-

@Override  protected Boolean doInBackground(Void... params) {      PermissionResponse response = PermissionEverywhere.getPermission(getApplicationContext(),       new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},              REQ_CODE,              "Notification title",               "This app needs  a write permission",               R.mipmap.ic_launcher)              .call();      //waits..      boolean isGranted = response.isGranted();      if(isGranted){ //changed from isGrante to isGranted      // Do stuff      }  }