简体   繁体   中英

Using FLAG_KEEP_SCREEN_ON across the Android system

The goal of my app is to keep the screen on across the whole Android system. Previously, I've used FULL_WAKE_LOCK for this and it allowed me to block dimming of the screen across the system. However, since the API Level 17, it got deprecated:

This constant was deprecated in API level 17. Most applications should use FLAG_KEEP_SCREEN_ON instead of this type of wake lock, as it will be correctly managed by the platform as the user moves between applications and doesn't require a special permission.

Official documentation recommends using FLAG_KEEP_SCREEN_ON , however it is possible to use it only for particular Activity .

I would still FULL_WAKE_LOCK , however I've found that it doesn't work now on some of the devices, like MediaPad Huawei x2, Redmi Note 3, etc. The way I'm currently using the PowerManager can be found on GitHub . Is there any better way to do accomplish this task after API level 17 ?

Starting with API 23 and its new Doze mode Wake Locks are ignored and they do not prevent the system from entering sleep.

You should experiment with maintaining a foreground service in parallel with the wake lock, theoretically that should prevent the device from entering sleep.

NOTE : the foreground Service has to call startForeground and show a non dismissable Notification

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM