Android 11 background location permission "Allow only while using the app" does not grant permission

Viewed 8097

As the title says, I'm currently in the process of updating my app to SDK 30 and having trouble with the ACCESS_BACKGROUND_LOCATION permission. Upon requesting the permission, the user is taken to the app location permission settings and is given 4 options:

  • Allow all the time
  • Allow only while using the app
  • Ask every time
  • Deny

All choices except "Allow all the time" do not grant the permission and return a -1 in the grantResults IntArray inside the onRequestPermissionsResult() callback function. Why? This is incredibly confusing. The naming would lead one to believe the permission would be granted and background permission requests only be made when the app is in focus. Is it possible to remove the "Allow only while using the app" option from the choices? How can I fix this?? I only see these choices confusing the user since the permission won't be granted unless they choose "Allow all the time".

1 Answers

Background location permission does not work like other permissions. It's a request to elevate location permission from foreground-only to foreground & background.

User has to consciously select "Allow all the time" in order to do that and grant background location permission. Otherwise that permission is considered denied.

You cannot even request background location unless foreground location is already granted - when system permission activity shows up it should already have option 2 or 3 selected.

See https://developer.android.com/training/location/permissions#request-background-location

Related