Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28049] Android: Investigate "ACCESS_BACKGROUND_LOCATION" handling on Android 11

GitHub Issuen/a
Resolution Date2020-09-19T06:09:32.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.3.0
Labelsandroid, location, permission
ReporterJoshua Quick
AssigneeJoshua Quick


*Summary:* Supposedly, Android 11 will no longer show a permission request dialog for the ACCESS_BACKGROUND_LOCATION permission. We need to confirm this. https://developer.android.com/preview/privacy/location#background-location-permission-dialog-changes If true, then the only way to enable permission is to go to the app's "Location Permissions" activity under system settings. This very well maybe true because according to Google's developer blog below, they will be removing apps using this permission from Google Play unless they provide a valid reason and pass Google's review process. https://android-developers.googleblog.com/2020/02/safer-location-access.html *Note 1:* We might be able to reach the app's "Location Permission" activity under system settings via the following intent action. ACTION_LOCATION_SOURCE_SETTINGS *Note 2:* We may need to expose Android's [shouldShowRequestPermissionRationale ()](https://developer.android.com/reference/android/app/Activity.html#shouldShowRequestPermissionRationale(java.lang.String)) API. Normally, this method would return true if the end-user tapped on "Disallow" in the permission request dialog. On Android 11, this might always return true for the ACCESS_BACKGROUND_LOCATION where you would have to tell the end-user how to enable it under system settings.




  1. Joshua Quick 2020-09-05

    Here are my test results... If you call requestPermission() for ACCESS_BACKGROUND_LOCATION and the app has *+NOT+* been granted ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, then a dialog will *+NOT+* appear and the method will report the permission as denied. This behavior exists on Android 10 as well. So, this is not an Android 11 breaking-change. If the app was granted the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission first and then you call requestPermission() for ACCESS_BACKGROUND_LOCATION, then a dialog will appear as shown below. What's different in Android 11 is the end-user must tap on the "*Allow in setting*" link to enable location access in the background. This is the major Android 11 change, but it doesn't require anyone to change their native or JS code to support this. Google merely added more steps to the UI to enable it on their end. !Android11-BackgroundLocationPermission.png|thumbnail! *Side Note:* A better solution for Android 10 and 11 would be to request for all 3 location permissions at once like the below. If you do, then a dialog will always appear... unless the end-user denied it several times already.
       var permissions = [
       if (Ti.Platform.Android.API_LEVEL >= 29) {
       Ti.Android.requestPermissions(permissions, function(e) {
       	alert("Has Location Permissions: " + e.success);
    !Android11-AllLocationPermissions.png|thumbnail! We should update our "Background Location Service Example" in our docs (link below) to request ACCESS_BACKGROUND_LOCATION as shown above. https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.Service *Final Notes:* We do not need to use a ACTION_LOCATION_SOURCE_SETTINGS intent to enable ACCESS_BACKGROUND_LOCATION. The "Allow in settings" link in the permission request dialog will take the end-user to that screen for us. We don't need to add a shouldShowRequestPermissionRationale() method. It's actually not helpful in this case.
  2. Joshua Quick 2020-09-10

    The current plan is to improve the Ti.Geolocation parity between Android and iOS, while also improving our APIs to make it easier to access the GPS in the background on both platform. This will be handled by the epic [TIMOB-28114]. \\ For now, the attached files below is an example of how to access GPS data in the background on both Android and iOS. This correctly works on Android 11 and older OS versions as well as iOS 14 and older iOS versions. * [^tiapp.xml] * [^GeolocationGpsTest.js] * [^GeolocationGpsService.js]
  3. Joshua Quick 2020-09-19

    The release version of Android 11 has completely changed behavior. It no longer displays a "Show in settings" link option as shown in the dialog screenshots above. More importantly, you can no longer ask for "ACCESS_BACKGROUND_LOCATION" and "ACCESS_FINE_LOCATION" in the same request anymore or else it will fail if you don't have any location permission at all. This is a breaking-change in the release version of Android 11. You now must request "ACCESS_FINE_LOCATION" first and then "ACCESS_BACKGROUND_LOCATION" second. Note that our docs currently suggest devs to do this already. https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.Service
  4. Samir Mohammed 2020-11-03

    Closing ticket as investigation is complete. If this is a mistake feel free to reopen.

JSON Source