Background Location Permission in Android 11 and above

Mohit Singh
2 min readJun 23, 2021

Request background location permission in all android versions using Java

With lastest android version Android 11, some security is added for location. Now to access background location, users have to manually “Allow all the time” in settings.

For using foreground and background location in lower versions of Android 11, we can take permission ACCESS_FINE_LOCATION, this permission will be considered for both foreground and background but with Android 11 and above you have to take one more permission ACCESS_BACKGROUND_LOCATION separately.

Ok now we will see how we can achieve background location permission for Android 11.

  1. Add these permissions in your mainfest file:

2. I added a simple button in activity_main.xml with id “location_permission”, on click of the button call checkPermission() function:

How we take permissions is explained in the above code.

After doing above steps, location permission is set to “Allow all the time”.

Points to note:

  1. If you ask for ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION at once then permission dialog will not shown. First ask for fine location and if user accepts then ask for background location.
  2. In Android Version lower than 11, ACCESS_BACKGROUND_LOCATION shows a dialog like this:

and in Android 11 and above, it looks like this:

For Android 11 and above, ACCESS_BACKGROUND_LOCATION opens up in settings.

Thanks for reading 🙌

Source Code : https://github.com/MohitSingh2002/location_permission_android_11

--

--