从Companion Mobile App环境模式唤醒磨损设备

时间:2014-07-16 05:43:10

标签: android wear-os wakeup powermanager ambient

我正在为Android Wear编写自定义观看面孔,我可以通过手机将设置数据发送到手表。但是,当手表处于环境模式且用户通过手机更改设置时,我想将手表从环境模式唤醒以显示手表的更新更改。

我尝试过使用Power Manager,但是我遇到了这个例外:

java.lang.IllegalArgumentException: Must specify a valid wake lock level.
            at android.os.PowerManager.validateWakeLockParameters(PowerManager.java:442)
            at android.os.PowerManager.newWakeLock(PowerManager.java:427)

我不理解这条消息,因为我在newWakeLock中设置了唤醒锁定级别。

这是我的代码:

private PowerManager.WakeLock mWakeLock;
private void wakeUpScreen(){
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    if(mWakeLock == null) {
        mWakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP, 
            "CubeWatch");
        Log.d(TAG, "WAKE UP!!!!");
        mWakeLock.acquire();
    }
    if(!mWakeLock.isHeld()) mWakeLock.acquire();  //if called a second time and isn't locked
    mHandler.removeCallbacks(mRunReleaseLock);    //if already waiting, then we'll start the time over 
    mHandler.postDelayed(mRunReleaseLock, 3000);
}
Handler mHandler = new Handler();
Runnable mRunReleaseLock= new Runnable() {
    @Override
    public void run() {
        mWakeLock.release();
    }
};

1 个答案:

答案 0 :(得分:1)

ACQUIRE_CAUSES_WAKEUP必须始终与FULL_WAKE_LOCK,SCREEN_BRIGHT_WAKE_LOCK,SCREEN_DIM_WAKE_LOCK和/或PARTIAL_WAKE_LOCK结合使用。

我目前正在使用

mWakeLock = powerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE), "wakeLock");

有效,但警告我有关SCREEN_BRIGHT_WAKE_LOCK和FULL_WAKE_LOCK的折旧。 SCREEN_DIM_WAKE_LOCK也已折旧。也许新的Wake Lock States为未来的Android Wear版本做好准备?像AMBIENT_WAKE_LOCK和INTERACTIVE_WAKE_LOCK这样的东西会很好。目前,SCREEN_BRIGHT_WAKE_LOCK和FULL_WAKE_LOCK工作正常。