The second Android 11 Developer Preview is now available, test it out and share your feedback.

Location updates in Android 11

Android 11 introduces changes to how apps can request the background location permission and how users can grant it. The specific changes depend on the app's target SDK version, but all apps that run on Android 11 are affected.

Background location access

Figure 1. In-app dialog for location permissions no longer includes the "Allow all the time" option

Android 11 further emphasizes user control over location information by adding one-time permissions and by removing the ability for users to grant the ACCESS_BACKGROUND_LOCATION permission from an in-app prompt, as shown in Figure 1.

All apps that run on Android 11 are affected by this change. The way that your app is affected depends on your app's target SDK version:

  • If your app targets Android 11, you can create a custom UI to explain to users why your app needs the ACCESS_BACKGROUND_LOCATION permission.
  • If your app targets a lower version, you must use the system-provided UI, which states that your app wants to access location information in the background, even when your app isn't being used.

Create a custom UI

If your app targets Android 11, you can show a custom UI that allows you to more clearly explain to users why your app needs the ACCESS_BACKGROUND_LOCATION permission.

Follow the guidelines in this section to create a UI that users are more likely to understand.

Explain your app's background location requirement

To request ACCESS_BACKGROUND_LOCATION in your app, your app must first get a foreground location permission—either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION. If you try to request ACCESS_BACKGROUND_LOCATION and any other permission at the same time, the system throws an exception.

After your app has one of these permissions, show a UI to the user where you offer features that need the ACCESS_BACKGROUND_LOCATION permission. This UI should include text that explains why your app's feature requires the ACCESS_BACKGROUND_LOCATION permission and present the user with a choice:

  • Grant the permission. If the user selects this option, make a permission request for ACCESS_BACKGROUND_LOCATION. The system directs the user to system settings to complete the process of granting this permission.

    To help users find the option in settings that allows them to grant the ACCESS_BACKGROUND_LOCATION permission, you can include the user-visible label of the settings option in your app's UI. The getBackgroundPermissionOptionLabel() method provides a label that's localized to the user's device language preference.

  • Don't grant the permission. Users should continue to be able to use your app if they don't grant the permission. If the user selects this option, your app can gracefully continue, possibly by navigating users away from the feature that requires background location access.

Even after your app is granted the ACCESS_BACKGROUND_LOCATION permission, keep in mind that users can change your app's location access to Allow only while using the app or Ask every time in system settings. They could also deny location access completely.

Direct users to system settings if necessary

Option is in the section titled 'Location access for
   this app'
Figure 2. Settings screen includes an option called Allow all the time, which grants background location access

If the user agrees to grant the ACCESS_BACKGROUND_LOCATION permission to your app, your app should direct the user to the settings screen that's shown in Figure 2. This screen includes the Allow all the time option, which grants your app the ACCESS_BACKGROUND_LOCATION permission.

Limited redirects to system settings

After your app navigates users to its permissions page in system settings, users might choose a level of location access other than Allow all the time, such as Deny. Android 11 allows your app to send users to system settings from a UI at most 2 times. Therefore, it's critical that you clearly explain to users why your app's feature requires access to background location.

When your app reaches this limit, you can still invoke an intent that directs users to your app's info page within system settings. From there, users can navigate to your app's permissions page. To load the app info page, use the Settings.ACTION_APPLICATION_DETAILS_SETTINGS intent action.

Caution: The use of ACTION_APPLICATION_DETAILS_SETTINGS is strongly discouraged, as it doesn't explain to users that your app is requesting the permission.

Use the system-provided UI

If your app targets Android 10 (API level 29) or lower, you must show a system-provided dialog, as shown in Figure 3, when you request the ACCESS_BACKGROUND_LOCATION permission:

In
  both versions of the dialog, the link for 'Allow in settings' appears before
  the other location permission options
Figure 3. Location permission prompts that include a link to system settings, both before any location permissions are granted (left) and after the user has already granted a foreground location permission (right)

This dialog includes the following:

  • Instructions on how to go to your app's location permissions page in system settings to select Allow all the time.
  • Buttons that grant foreground location access, or a button that denies an upgrade to background location access.