Permission Permutations

There have been some tweaks to how runtime permissions work in Android 11. In theory, most of these should not cause any harm to your app. Unfortunately, not everything works the way that we think it should, and so it is possible that you will need to make some tweaks to your app to accommodate these changes.

And, if you are using location permissions, and adjusted your app to deal with background locations for Android 10… you have more work to do here in Android 11.

One-Time Permissions

The biggest user-visible change is what Google calls “one-time permissions”. For a certain set of permission groups, the user will be given an “Only this time” option in the runtime permission dialog:

Runtime Permission Dialog with Only This Time Option
Runtime Permission Dialog with “Only This Time” Option

The documentation is a bit unclear over exactly which permissions get this treatment. Based on what is written, it is likely that the permissions in the CAMERA, LOCATION, and MICROPHONE permission groups will be affected.

The documentation is also a bit vague on how long the permission grant remains in effect — in others words, what is the scope of “Only this time”? Based on experiments, it appears that the answer is “for the current process”, where a fresh process will need to bring up the permission dialog again… if that process is launched a bit after the old process ended.

Trying It Out

You can test this yourself using the PermissionCheck sample module in the book’s sample project.

When you run this module, you get an activity with a Switch to request the ACCESS_FINE_LOCATION runtime permission:

PermissionCheck App, As Initially Launched
PermissionCheck App, As Initially Launched

That switch will be off and enabled if you do not hold the permission at the time of displaying the activity, and it will be on and disabled if you do hold the permission. Also, the “Request Location” button beneath it will be enabled if you hold the permission — clicking it will find your location and display it where you see “(no location)” in the screenshot. Finally, the “Launch Another Activity” button launches another instance of this activity, where the code in the toolbar will show you which instance is which.

If you click the switch and grant the permission “Only this time”, you will find that:

Ramifications For You

In theory, your app should already handle this. After all, the user could revoke your runtime permission from the Settings app at any point. Your process is then terminated (if it was running), and the next time your app runs, you will need to request permission again. All “Only this time” does is automate that work.

The documentation implies that the scope of an “Only this time” permission is a single activity, or perhaps the combination of an activity and a foreground service. Most likely, this is just a documentation bug. However, you may wish to pay closer attention to this change as Android 11 evolves, in case they revise the behavior to match the documentation.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.