To further protect user privacy, Android 11 adds one-time location access and changes how users grant background location access. These updates affect all apps that run on Android 11.
On Android 11, whenever your app requests access to foreground location, the system permissions dialog includes an option called Only this time, as shown in figure 1. This new option give users more control over when an app can access location information.
Learn more about changes to permissions in Android 11.
Background location access
Android 11 changes how a feature in your app can gain access to background location. This section describes each of these changes.
Request background location separately
As described in the guide on how to request location access at runtime, you should perform incremental location requests. If your app targets Android 11, the system enforces this best practice. If you request foreground location and background location at the same time, the system ignores the request.
Permission dialog changes
How to toggle
As you test your app's compatibility with Android 11, you can toggle this change on or off using the following ADB commands:
adb shell am compat enable (147316723|BACKGROUND_RATIONALE_CHANGE_ID) PACKAGE_NAME
adb shell am compat disable (147316723|BACKGROUND_RATIONALE_CHANGE_ID) PACKAGE_NAME
For more information about the compatibility framework and toggling changes, see Test your app's compatibility with Android 11.
When a feature in your app requests background location on a device that runs Android 11, users no longer see a system dialog that includes a button to enable background location access. In order to enable background location access, users must set the Allow all the time option for your app's location permission on a settings page, as shown in figure 2.
You can help users navigate to this settings page by following best practices when requesting the runtime permission for background location. The process for granting the permission depends on your app's target SDK version.
App targets Android 11
true, show an educational UI to users that includes the following:
- A clear explanation of why your app's feature needs access to background location.
- The user-visible label of the settings option that grants background location
(for example, Allow all the time in figure 2). You can call
getBackgroundPermissionOptionLabel()to get this label. The return value of this method is localized to the user's device language preference.
- An option for users to decline the permission. If users decline background location access, they should be able to continue using your app.
App targets Android 10 or lower
When a feature in your app requests background location access, users see a system dialog. This dialog includes an option to navigate to your app's location permission options on a settings page.
If your app already follows best practices for requesting location permissions, you don't need to make any changes to your app in order for this new behavior to work.