Android: get location as Foreground Service (without accessing background location)

  1. SDK Version:40
  2. Platforms(Android/iOS/web/all): Android

Due to the recent changes in Google Play Store regarding background location permissions, I am trying to get our app to conform to the new guidelines (Requesting access to location in the background - Play Console Help). The app is an activity tracker that tracks where the user has been between pressing “record” and “stop”, similar to fitness trackers like Strava.

Naturally I’d like the location updates to keep coming even if the app is not in focus, and I don’t mind a foreground service notification saying that my app is tracking the location. As far as I can see from the new guidelines, they want these kinds of apps to not ask for background location permissions, and instead use a foreground service (that will keep the app in a foreground state, so the location updates will keep coming). I can’t seem to make this work with Expo. I have tried two approaches:

1: use startLocationUpdatesAsync with the foregroundService property - this now fails because in order to use this method, I need to request BACKGROUND_LOCATION permission, which is exactly what I do not want to do.
2: use watchPositionAsync, but that only works when app is focused, and I can’t see any way to make a foregroundService.

Does anyone know if I can somehow achieve getting location updates from an app with a foreground service without asking for BACKGROUND_LOCATION permission? Any help would be greatly appreciated.

@hansbergheim I have exactly the same need for same type of app and did plenty of googling to find the answer. Got yesterday a good answer from Expo team in Expo Github:

In short: solution is coming in SDK41, which is hopefully available soon, and implements latest Google Play Store guidelines for all recent Android versions (with location & permission API having changed in all of them…).

@marasu thanks for the info. Good thing it’s coming. :+1: Unfortunately the deadline is in the end of March, so I saw no other option than doing the required UI fixes and create a youtube video explaining the functionality as they required, and then applying for background location access. The app is in review now, so fingers crossed :slight_smile:

@hansbergheim let us know the result of the app review as I was wondering the same should SDK41 be delayed or there be any issue in the implementation. New Google policy guidelines seem to be rather strict specifically not supporting background access for type of apps that can do with the foreground location service…

The reivew appears to have gone well :slight_smile: My first submission got turned down because there was no link to our privacy policy within our app, but once I added that it seems to not be flagged in violation of any of the new policies.

Lets hope the new SDK41 comes out with proper fixes for this, so we don’t have to jump through these hoops for all of our apps with this functionality.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.