从同伴移动应用程序唤醒穿戴设备从环境模式



我正在为Android Wear编写一个自定义表盘,我可以从移动设备向手表发送设置数据。但是,当手表处于环境模式并且用户从移动设备更改设置时,我想从环境模式唤醒手表以显示更新的更改。

我尝试使用电源管理器,但我得到这个异常:

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();
    }
};

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工作得很好。

相关内容

  • 没有找到相关文章

最新更新