如何在没有AlarmManager的情况下使用Android的传感器批处理 [英] How to use Android's Sensor Batching without AlarmManager

查看:83
本文介绍了如何在没有AlarmManager的情况下使用Android的传感器批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:


使用该计算通过AlarmManager设置唤醒警报,该警报将调用您的Service(实现SensorEventListener)以刷新传感器。

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秒(请参阅此处),所以这行不通吗?是否有其他方法可以在更短的时间内唤醒设备,或者更好(就电池效率而言)可以持续保持唤醒锁?我猜这60秒的约束将有其原因。

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.

推荐答案

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

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:


注意:从API 19开始,所有重复的警报都是不精确的。如果您的应用程序需要精确的交付时间,则它必须使用一次精确的警报,并按如上所述每次重新安排。

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 ),并且当该警报触发时,您需要自己重新安排时间。

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.

这篇关于如何在没有AlarmManager的情况下使用Android的传感器批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆