Reference:
http://stackoverflow.com/questions/2891337/turning-on-screen-programmaticallyAdvance:
Turn on screen and dismiss keyguard
http://stackoverflow.com/questions/30246425/turning-on-screen-from-receiver-service
Code snippet:
在需要打開螢幕的地方加入下面的 codeWakeLock wl = ((PowerManager)getSystemService(POWER_SERVICE)).newWakeLock(
PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire();
在離開前要記得釋放 wake lock,以免螢幕保持開啟,造成耗電的問題
wl.release();
Note:
釋放 (release)的 wake lock要和獲取 (acquire)的是同一個,不要再重新建立一個新的wake lock,否則釋放 wake lock時會不能正常運作
沒有留言:
張貼留言