简体   繁体   English

Android Wear-如何(如果可能)使处理器在环境模式下保持唤醒状态?

[英]Android Wear - How (if possible) to keep processor awake in ambient mode?

With the new addition of the "always on" api in a recent update with android wear, naturally I am trying to incorporate it into my fitness application. 随着androidwear的最新更新中新增加的“ always on” api,我自然会尝试将其合并到我的健身应用程序中。 After doing some heavy reading on the android developers website it seems as though the only way to wake up the processor in ambient mode is to use an alarm manager. 在android开发人员网站上进行了大量阅读后,似乎在环境模式下唤醒处理器的唯一方法是使用警报管理器。 However this method is not very consistent or accurate. 但是,此方法不是非常一致或准确。

1) With the alarm set to wake the processor and change the time on the screen after 3 seconds, it bounces around between 5-10 seconds. 1)将警报设置为唤醒处理器并在3秒后更改屏幕上的时间,它会在5-10秒之间跳动。

2) Most of the time the method onEnterAmbient() is not even called until about a minute into being in ambient mode (the handler is still running and updating the screen at normal frequency) 2)在大多数情况下,直到进入环境模式约一分钟时才调用onEnterAmbient()方法(处理程序仍在运行并以正常频率更新屏幕)

3) Overall if anyone knows a different way to push updates to the screen while in ambient mode that would fantastic! 3)总的来说,如果有人知道在环境模式下将更新推送到屏幕的另一种方法,那就太好了! (Mainly I believe there is another way due to the fact that watchfaces are able to update and show animations every second while in ambient mode) (主要是我相信,由于在环境模式下表面能够每秒更新和显示动画的事实,因此还有另一种方法)

You can keep processor running in ambient mode by utilizing wake lock: 您可以通过利用唤醒锁定使处理器在环境模式下运行:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "awake");
wl.acquire(30000);  // with 30s timeout or manually via wl.acquire() wl.release()

But you must take into consideration increased power usage which is not good idea in ambient mode. 但是您必须考虑增加的功耗,这在环境模式下不是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM