Android PowerManager WakeLock – Deprecated-ThrowExceptions

Exception or error:

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?

How to solve:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *