The Android SDK tells me that PowerManager.SCREEN_DIM_WAKE_LOCK
and similar constants are deprecated as of API Level 17. It also says that FLAG_KEEP_SCREEN_ON
can be used in most situations.
But what if this is not the case? In particular, I want to be able to have the screen dimmed but not shut off entirely. What are other, "better" alternatives – or aren't there simply any?
Obtain a wake lock by calling PowerManager#newWakeLock(int, String) . Call acquire() to acquire the wake lock and force the device to stay on at the level that was requested when the wake lock was created. Call release() when you are done and don't need the lock anymore.
A wake lock is a mechanism to indicate that your application needs to have the device stay on. Any application using a WakeLock must request the android. permission. WAKE_LOCK permission in an <uses-permission> element of the application's manifest.
PARTIAL_WAKE_LOCK. Wake lock level: Ensures that the CPU is running; the screen and keyboard backlight will be allowed to go off.
Samsung S6 with Android 7.0: Settings > Device maintenance > Battery > Power saving mode: Off. Settings > Device maintenance > Battery > Unmonitored apps: Add RaceChrono and/or RaceChrono Pro to the unmonitored list.
There is currently no better alternative as to actually use the deprecated WakeLock.
Actually you have another alternative (but not better). You can use the FLAG_KEEP_SCREEN_ON
in combination with changing the system brightness manually from inside your activity (example).
But what if this is not the case?
I'm having a similar situation in which I need the screen to be constantly on from a Service
(so the Activity.getWindow() is not available). In this case i use the deprecated WakeLock until Android comes up with a new API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With