I'm writing a Custom Watch Face for Android Wear, and I am able to send settings data to the watch from mobile just fine. However when the watch is in ambient mode and the user changes the settings from their mobile, I'd like to wake the watch from Ambient Mode to show the updated changes to the watch.
I've tried using Power Manager, but I get this exception:
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)
I don't understand this message because I set the wake lock level in newWakeLock.
Here's my Code:
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();
}
};