Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I replace SCREEN_DIM_WAKE_LOCK with?

I am currently utilizing the below referenced code for a wake lock on an alarm notification activity. However, SCREEN_DIM_LOCK has been depreciated. So, what should I be replacing it with?

//Instance of wake lock for AlarmActivity
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "MyWakeLock");
like image 963
user3391426 Avatar asked Mar 17 '14 05:03

user3391426


People also ask

How do I get Wakelock on my Android?

Your app acquires a partial wake lock by calling acquire() with the PARTIAL_WAKE_LOCK flag. A partial wake lock becomes stuck if it is held for a long time while your app is running in the background (no part of your app is visible to the user).

What is Partial_wake_lock?

Wakelocks. By monitoring the contents of the /sys/power/wake_lock file (root access required), you can see that the PARTIAL_WAKE_LOCK is the only wakelock that stays in effect after the power button is pressed. The other wakelocks keep the display from turning off, with various brightness levels.

What are the wake locks available in Android?

Options 1) finish() 2) getGPSStatus() 3) onProviderDisable() 4) getGPS().


2 Answers

Android Developer documentation specifies that SCREEN_DIM_WAKE_LOCK should be replaced with FLAG_KEEP_SCREEN_ON. After doing a bit of digging, I turned up this...

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

It should be placed in the onCreate() method.

like image 76
user3391426 Avatar answered Sep 17 '22 17:09

user3391426


It can be replaced for FLAG_KEEP_SCREEN_ON, as the javadoc says, but this will prevent the screen from dimming - it will remain bright.

This API should not have been deprecated - it is still needed in some cases, such as the "dim" case.

See also this.

like image 27
Oliv Avatar answered Sep 21 '22 17:09

Oliv