Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GPS locations tracking in background on android 7

I have app for android that needs to send on regular intervals (let's say every 10 s) an location update to the server. So far nothing special. However this is done completely in the background as an service. This app uses LocationManager to regulary receiving the current GPS location and send this to the server. This this of course the simplified story of the app, just focussing on the issue

The complete app is working ok until android 6. In android 6 the app stops sending updates when the sreens is off after a while, but comes alive again after movement, screen on or charging. This caused by the Doze function, this is oke. As long the the app sends location updates after movement.However on Android 7 the location updates are only received on the server when the screen is on or charging. Movement (like walking) does not trigger to turn of Doze (at least no location updates are received on the server). The app is alos whitelisted for battery optimization, but that doesn't help. Probably by the the GPS/network is turn off.

Reading the Android documention, I don't see a sollution for receiving and sending the current GPS locations at interval controlled by the app in the background when the device is Doze.

Is there a sollution or can give somebody a direction to solve this GPS problem I have for android 7?

Thanks.

like image 546
Kristian Avatar asked Nov 07 '22 20:11

Kristian


1 Answers

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

like image 72
Kristian Avatar answered Dec 01 '22 21:12

Kristian