I'm creating an app to connect with BT device to collect heath data (i.e.: body temperature).
The sensor sleeps for periodic time and wakes up only for limited window of time to connect.
I've tried to create AlarmManager which fires Foreground Service with setExactAndAllowWhileIdle()
and it is working as expected for periods higher than 9 minutes,
but below 9 minutes it goes to doze mode and do not fire AlarmManager BroadcastReceiver.
From documentation I do not understand if adding app to battery optimalization whitelist will allow AlarmManager to trigger more offen
https://developer.android.com/training/monitoring-device-state/doze-standby#support_for_other_use_cases
For example, the whitelisted app’s jobs and syncs are deferred (on API level 23 and below), and its regular AlarmManager alarms do not fire
What are the regular alarms? is setExactAndAllowWhileIdle()
regular?
Any clarification will be appreciated
EDIT:
I understand that setExactAndAllowWhileIdle()
will trigger event in doze mode for periods longer than 9 minutes, question is does adding app to whitelist will allow it to trigger more often
What are the regular alarms ? is setExactAndAllowWhileIdle() regular ?
No. setExactAndAllowWhileIdle()
is not regular. Regular alarm could be AlarmManager alarms set though setExact() and setWindow().
but below 9 minutes it goes to doze mode and do not fire AlarmManager
BroadcastReceiver
It has restrictions on how frequently you can set alarm.
Based on the documentation:
To reduce abuse, there are restrictions on how frequently these alarms
will go off for a particular application. Under normal system
operation, it will not dispatch these alarms more than about every
minute (at which point every such pending alarm is dispatched); when
in low-power idle modes this duration may be significantly longer,
such as 15 minutes.
You can refer to Doze restrictions which says:
Standard AlarmManager alarms (including setExact() and setWindow())
are deferred to the next maintenance window.
- If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
- Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire
For Whitelist:
Apps available in whitelist are partially exempt from Doze and App Standby optimizations. This doesn't mean they have full access to and could perform tasks during doze mode. An app that is whitelisted can use the network and hold partial wake locks during Doze and App Standby. However, other restrictions like jobs being differed, standard alarm trigger are still imposed
Note: You should check acceptable usecases for whitelisting an app.
Google Play policies prohibit apps from requesting direct exemption
from Power Management features in Android 6.0+ (Doze and App Standby)
unless the core function of the app is adversely affected.