问题
I want to use Androids sensor batching introduced in Android 4.4 to save some battery power. My testing device can store 184 sensor events in its fifo-queue. Using a sampling rate of 18 events/seconds I have to flush the sensor about every 10 seconds. The section on Sensor Batching in the 4.4 Documentation proposes:
Use that calculation to set wake alarms with AlarmManager that invoke your Service (which implements the SensorEventListener) to flush the sensor.
Since Android 5.1 the minimum wake-up-interval for the AlarmManager is 60 seconds (see here), so this won't work? Is there an alternative for waking up the device in shorter time periods or is even better (in terms of battery efficiency) to hold a wakelock constantly? I guess the 60-seconds-constraint will have its reasons.
回答1:
The 60 second minimum only applies to repeating alarms. For one-off exact alarms, you can have much smaller delays. The documentation mentions this as well:
Note: as of API 19, all repeating alarms are inexact. If your application needs precise delivery times then it must use one-time exact alarms, rescheduling each time as described above.
In practice, this means you'll need to schedule an exact alarm (using setExact
), and when that alarm has fired, you'll need to take care of rescheduling it yourself.
来源:https://stackoverflow.com/questions/35746009/how-to-use-androids-sensor-batching-without-alarmmanager