Premise
The user should always be informed of the use of his sensitive data (like collecting the location in the background), this question aims to better understand the latest limitations introduced on Android use of location and background operations.
Problem
Is it still possible (on Android latest versions) to create a location tracking service that would keep tracking the device location no matter the application state (foreground / background) nor the device state (doze or standby mode, app buckets) in order to be able to collect location in a consistent way ?
Assuming that the GPS and internet connection are enabled and available, is it possible to collect the location, let's say every 10 minutes, or the device going to doze mode or standby will anyway restrict the app possibilities after some time and defer the operations (like network operations), making it impossible to keep getting regular location updates ?
On latest android versions, starting from Android 8.0 (API 26), new ways to improve battery performance and secure the users privacy have been introduced:
What I tried
From my understanding, a foreground service looks like the best option:
- keep informing the user (notification)
- the system does not kill the service after a few seconds (as for background services starting from API 26)
- less likely to get stopped by the system (START_STICKY flag to restart otherwise)
- can acquire a wake lock
Still it seems that the app needs to be whitelisted to avoid battery optimisations and even battery optimisation need to be disabled in order for the service not to be stopped/deferred.
Expected result
Receive location updates at regular intervals, every 10 minutes for instance