Track GPS locations in the background on Android 7

I have an android application that needs to be sent at regular intervals (albeit every 10 seconds) to update the location on the server. Nothing special yet. However, this is done entirely in the background as a service. This application uses the LocationManager to regularly obtain the current GPS location and send it to the server. This, of course, is a simplified application history that simply focuses on the problem.

The full application works fine until android 6. In android 6, the application stops sending updates when the screens are turned off after a while, but comes back to life after movement, turning on the screen or charging. This is called the Doze function, this is oke. While the application sends location updates after movement. However, on Android 7, location updates are only accepted on the server when the screen is on or charging. Movement (e.g. walking) does not cause a Doze turn (at least no location updates are received on the server). The app is alos whitelisted for battery optimization, but it does not help. The GPS / network is probably disconnecting.

Reading the Android documentation, I don’t see permission to receive and send current GPS locations at intervals controlled by the application in the background when the device is Doze.

Is there any permission or can give someone direction to solve this GPS problem that I have for Android 7?

Thank.

+4
source share
1 answer

Found a solution for this. Make sure this is a foreground function instead of a backgorund. A good article can be found at https://developer.android.com/preview/features/background-location-limits.html

0
source

Source: https://habr.com/ru/post/1679779/


All Articles