1

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?

yyunikov
  • 5,719
  • 2
  • 43
  • 78

1 Answers1

0

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

from56
  • 3,976
  • 2
  • 13
  • 23
  • I'm aware of `Doze` mode and keeping the background service is actually what I'm currently doing, but unfortunately this doesn't work on some of the devices. You can check my implementation here: https://github.com/yyunikov/android-dim-block/blob/master/src/main/java/com/yyunikov/dimblock/service/DimBlockService.java#L31 – yyunikov Jul 09 '17 at 11:57
  • I added a Note, your Notificaction class should call builder.setOngoing(true); ... I think. – from56 Jul 09 '17 at 13:21
  • Just tried it - Foreground service alone won' keep screen from dimming out or going to sleep. Implementing wake lock in foreground service does prevent screen from going to sleep, but it still dimms. – Starwave Mar 13 '20 at 22:16