Doze Mode Handling
Solution 1:
You can not "break"/stop/disable doze mode, but there are ways to temporarily lift your app's restrictions while the device is dozing.
- A high priority FCM message.
FCM high-priority messages let you reliably wake your app to access the network, even if the user’s device is in Doze or the app is in App Standby mode. In Doze or App Standby mode, the system delivers the message and gives the app temporary access to network services and partial wakelocks, then returns the device or app to the idle state.
High-priority FCM messages do not otherwise affect Doze mode, and they don’t affect the state of any other app. This means that your app can use them to communicate efficiently while minimizing battery impacts across the system and device.
- An
andAllowWhileIdle
alarm set with AlarmManager.
Doze is particularly likely to affect activities that AlarmManager alarms and timers manage, because alarms in Android 5.1 (API level 22) or lower do not fire when the system is in Doze.
To help with scheduling alarms, Android 6.0 (API level 23) introduces two new AlarmManager methods: setAndAllowWhileIdle() and setExactAndAllowWhileIdle(). With these methods, you can set alarms that will fire even if the device is in Doze.
Note that the minimum interval between two alarms in doze mode is 9 minutes.
For both cases, your app is restored to full functionality (meaning: the doze restrictions do not apply) for a short period of time, when that time expires, the OS will reinstate the doze restrictions.
Note that you do not need to turn on the screen to execute code during either of these 'wake up' periods.
I don't have a source at hand, but I believe the short period I name is ~10 seconds.
Post a Comment for "Doze Mode Handling"