Say you have a method like this:
public boolean saveFile (Url url, String content) {
// save the file, this can be done a lot of different ways, but
// ba
As of Marshmallow, my understanding is that you can't.
I had to solve the same issue in my app. Here's how I did it:
.
if (ContextCompat.checkSelfPermission(this, Manifest.permission.SOME_PERMISSION) == PackageManager.PERMISSION_GRANTED)
doStuffThatRequiresPermission();
else
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SOME_PERMISSION}, Const.PERM_REQUEST_DO_STUFF_THAT_REQUIRES_PERMISSION);
onRequestPermissionsResult()
in every Activity
that asks for permissions. Check if the requested permissions were granted, and use the request code to determine what method needs to be called.Be aware that the API requires an Activity
for runtime permission requests. If you have non-interactive components (such as a Service
), take a look at How to request permissions from a service in Android Marshmallow for advice on how to tackle this. Basically, the easiest way is to display a notification which will then bring up an Activity
which does nothing but present the runtime permissions dialog. Here is how I tackled this in my app.