开发者

reset screen timeout in android

开发者 https://www.devze.com 2023-02-19 13:23 出处:网络
I\'m using the following code to wake the phone\'s screen: PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

I'm using the following code to wake the phone's screen:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "XPAND-IT");
wl.acquire();

After this code runs, I want t开发者_开发技巧o reset the screen timeout to release the wake lock. How can I do it?


I assume you have the following problem:

  • The wake lock is acquired
  • Some time passes without the user touching the screen
  • The wake lock is released
  • The screen goes off immediately (or at least too soon) because the screen timeout period started counting when the wake lock was acquired

There's a simple solution for this: Add the flag PowerManager.ON_AFTER_RELEASE and the timeout is reset when releasing the wake lock.

0

精彩评论

暂无评论...
验证码 换一张
取 消