8

I have an app which updates the location to a web service every 10 seconds. However, on devices with API level 23 or greater, when doze mode kicks in after 15 minutes to inactivity, the network connectivity is lost, and the app becomes unable to send further location updates to my web service.

Other than whitelisting the app by asking for user permission to ignore battery optimizations, which only allows a location update once every 15 minutes, what are my other options to keep getting GPS location updates and be able to send them to my web service?

Ashik Vetrivelu
  • 1,021
  • 1
  • 9
  • 24
Zishan Neno
  • 2,647
  • 7
  • 34
  • 58

2 Answers2

3

Though it is highly immoral to overcome doze mode, if the app can explain the issue with the battery to the user then it is better to whitelist the app.

The other option is to keep the screen on to avoid doze mode from getting triggered.

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

This piece of code will keep the screen on. Make sure to create a black or empty layout like what battery saver in pokemon go does.

The Official Doze documentation allows whitelisting for your use case. Check it here.

Ashik Vetrivelu
  • 1,021
  • 1
  • 9
  • 24
0

You're running way too often to begin with. There's no phone that even updates location that fast- normal would be once every 30 to 60 seconds. So 2/3 to 5/6 of your updates are pointless. Ignoring that- if you're in a car going 60 mph you aren't going to change by more than 14 feet in 10 seconds. There's absolutely nothing you're doing on the server that needs to be accurate to 14 feet- the typical GPS in a phone is only accurate to 10 meters (over 30 feet). That's one of the reasons why GPS doesn't update more frequently.

But no, there isn't. They implemented Doze for a reason. It saves battery. They set it up so you can't get around it without asking the user if they want to burn that battery. I definitely understand why 15 minutes is too slow, but then you ask the user and let them decide if your app is worth it.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • I think the point the SO is making is irrespective of whether it is 10 seconds or even a minute, how can they make network requests out when in doze mode? So for example, if they are developing a driver navigation app. Is it therefore via sending a GCM high priority message? – AshesToAshes Jan 05 '17 at 06:59
  • @AshesToAshes They request to be whitelisted. He's trying to do it without that. (Google Maps comes whitelisted by the OEM). THe part about it being too frequent is me pointing it out so he stops wasting network bandwidth and battery power doing pointless things. – Gabe Sechan Jan 05 '17 at 07:00
  • Very true, but is the answer to get around this to whitelist the app which is a must + GCM messages then? – AshesToAshes Jan 05 '17 at 07:01
  • @AshesToAshes If its whitelisted he doesn't need GCM. Read his question- he's just trying to avoid asking the user for whitelisting. – Gabe Sechan Jan 05 '17 at 07:03
  • Ok, but what happens when I request the user to whitelist my app (as in this post: http://stackoverflow.com/questions/32316491/network-access-in-doze-mode?rq=1) and they grant the permission? Would I be able to periodically send updates to my web service? – Zishan Neno Jan 05 '17 at 07:04