简体   繁体   中英

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.

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.

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.

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 . To become it active i have just found that only FULL_WAKE_LOCK works. 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.

Based from the documentation , you can obtain an instance of PowerManager class by calling Context.getSystemService() .

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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