如何在没有 AlarmManager 的情况下使用 Android 的传感器批处理

How to use Android's Sensor Batching without AlarmManager

我想使用 Android4.4 中引入的 Androids 传感器批处理来节省一些电池电量。我的测试设备可以在其 fifo 队列中存储 184 个传感器事件。使用 18 events/seconds 的采样率,我必须大约每 10 秒冲洗一次传感器。 4.4 Documentation 中关于传感器批处理的部分建议:

Use that calculation to set wake alarms with AlarmManager that invoke your Service (which implements the SensorEventListener) to flush the sensor.

由于 Android 5.1,AlarmManager 的最小唤醒间隔为 60 秒 (see here),所以这行不通吗?有没有一种方法可以在更短的时间内唤醒设备,或者更好(就电池效率而言)不断保持唤醒锁?我猜 60 秒限制会有它的原因。

60 秒的最小值仅适用于重复 警报。对于一次性精确警报,您可以有更小的延迟。 documentation 也提到了这一点:

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.

实际上,这意味着您需要安排一个确切的警报(使用 setExact),并且当该警报触发时,您需要自行重新安排。