How to use Android's Sensor Batching without AlarmManager

拟墨画扇 提交于 2019-12-23 17:19:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!