简体   繁体   English

部分唤醒锁不能用于安装

[英]Partial wakelock does not work on android wear

I'am gathering accelerometer data in my watchface and as soon as the device enter ambient mode the cpu is put to sleep. 我在表盘中收集加速度计数据,一旦设备进入环境模式,cpu就会进入睡眠状态。

I've tried adding a partial_wakelock on creation but it still does not work, A Full wakelock works fine but i want the benefits of having ambient mode such as burn in protection to work. 我已经尝试在创建时添加了partial_wakelock,但它仍然不起作用,完整的唤醒锁定工作正常,但我希望使用环境模式(如保护中的烧伤)来工作。

Any idea whats wrong? 有什么想法错了吗?

        powerManager = (PowerManager) getSystemService(POWER_SERVICE);
        //wl = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "awake");

        wl = powerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MyWakelockTag");

The commented line does not work. 注释行不起作用。

I aquire the wakelock in registration of the accelerometer and release it onDestroy. 我在加速度计的注册中获取唤醒锁并将其释放到onDestroy。

It is a very frustrating problem and i can not find out what iam doing wrong. 这是一个非常令人沮丧的问题,我无法找出我做错了什么。

In breif it is normal. 简而言之,这是正常的。 Relax. 放松。

For battery saving reason some Android devices go to sleep and disable bluetooth mode . 出于节省电池的原因,一些Android设备进入睡眠状态并禁用蓝牙模式。 To become it active i have just found that only FULL_WAKE_LOCK works. 为了变得活跃,我刚刚发现只有FULL_WAKE_LOCK有效。 May be, i'm bot right but this is my experince. 可能是,我是机器人,但这是我的经验。 The other options that helps to save battery must be disabled inside Android OS preference too. 必须在Android OS首选项中禁用其他有助于节省电池的选项。

Based from the documentation , you can obtain an instance of PowerManager class by calling Context.getSystemService() . 根据文档 ,您可以通过调用Context.getSystemService()获取PowerManager类的实例。

You may want to try using this: 您可能想尝试使用此:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

instead of 代替

powerManager = (PowerManager) getSystemService(POWER_SERVICE);

In addition to that, you cannot use ACQUIRE_CAUSES_WAKEUP and ON_AFTER_RELEASE with PARTIAL_WAKE_LOCK . 除此之外,您不能将ACQUIRE_CAUSES_WAKEUPON_AFTER_RELEASEPARTIAL_WAKE_LOCK ON_AFTER_RELEASE使用。

Please also note that any application using a WakeLock must request the android.permission.WAKE_LOCK permission in an <uses-permission> element of the application's manifest. 另请注意,使用WakeLock的任何应用程序都必须在应用程序清单的<uses-permission>元素中请求android.permission.WAKE_LOCK权限。

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

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