6

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".

SpecialSnowflake
  • 945
  • 4
  • 16
  • 32

1 Answers1

4

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

Pawel
  • 15,548
  • 3
  • 36
  • 36
  • 4
    Also to note that new apps submitted to playstore requesting `ACCESS_BACKGROUND_LOCATION` require you to fill in a Permissions Declaration form which includes having to show video evidence of your app explicitly telling the user why you require the permission and explain your feature. https://support.google.com/googleplay/android-developer/answer/9799150 – Mark Feb 22 '21 at 19:25