我正在为 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();
}
};