Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android PowerManager WakeLock – Deprecated

Tags:

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?

like image 687
Ingo Bürk Avatar asked Jan 09 '13 00:01

Ingo Bürk


People also ask

How do I get Wakelock on Android?

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.

What is Wakelock permission Android?

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.

What is Partial_wake_lock?

PARTIAL_WAKE_LOCK. Wake lock level: Ensures that the CPU is running; the screen and keyboard backlight will be allowed to go off.

How do I turn off power manager on Android?

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.


1 Answers

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.

like image 147
Twinone Avatar answered Sep 23 '22 07:09

Twinone