Reputation: 2817
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?
Upvotes: 8
Views: 1405
Reputation: 1041
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.
Upvotes: 3
Reputation: 93668
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.
Upvotes: 0