Home » Android » Preventing Standby and doze for location service

Preventing Standby and doze for location service

Posted by: admin November 1, 2017 Leave a comment


I have a background location service bound to the main activity of my mobile app. It fires a handleLocationChanged event handler on my main activity. If app is stopped or backgrounded, it continues to fire this event and the event handler in main activity send out a location via the network. However, it stops when the phone goes into standby or doze mode. I have read all about batter optimization settings, creating intents to let users change this, ask for batter optimization permissions etc…

So I manually added my app to my phone’s “white list” as many posts I’ve seen have suggested and it still doesn’t always work.

But I noticed that I did not see my music app on this white list nor gmaps, but gmaps continues to give out voice directions and music app continues to play, no matter what happens. In fact, I can’t seem to ever completely shut my music app off, I just have to pause it.

So how are they pulling this off? Does it have to do with the fact that they are receiving rather than sending?

My app receives things, but it also it sends location out via the mobile network, and that’s the most important part that I need to keep running.

I’ve seen suggestions about creating a foreground service in a separate thread and using notifications, but that seems like that is for receiving and the notifications are merely let through as an exception, and that seems to make a big difference for waking the phone or keeping it on. But it seems like there is nothing I can do about sending. Does anybody have any ideas about what could work? Thank you.