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?
Tap the Options menu button (the three dots in the upper right), then tap Battery optimization. Tap the downward-pointing arrow, then tap All apps from the menu that appears. Next, tap the PsyMate app for which you want to switch off Doze mode, and in the box that appears, tap Don't optimize.
Where appropriate: select Android or iOS. Select App Management. Then click on Blacklist/Whitelist, click configure and select Whitelist. Select +Add to either an app or App group.
Doze mode and App Standby If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting apps' access to network and CPU-intensive services.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With