我想使用 Android 4.4 中引入的 Android 传感器批处理来节省一些电池电量。我的测试设备可以在其 fifo 队列中存储 184 个传感器事件。使用 18 个事件/秒的采样率,我必须大约每 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
),并且当该警报触发时,您需要自行重新安排。
关于android - 如何在没有 AlarmManager 的情况下使用 Android 的传感器批处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35746009/