0

Im trying to create a program to keep the keyboard backlight on if the screen is on. Im very new to android but i have been programming java for 6months. Im not sure how to use the constant Full_Wake_Lock to keep the kb lgiht on.

Adrian Le Roy Devezin
  • 672
  • 1
  • 13
  • 41

2 Answers2

0

BEFORE: wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

AFTER: wakeLock = pm.newWakeLock(PowerManager.ON_AFTER_RELEASE, "DoNotDimScreen");

Bay
  • 467
  • 7
  • 22
0

You would need to start a Service.
Then you would have to acquire the wake lock within the onCreate, then in the onDestroy you would release the WakeLock. That is if you are trying to hold the wake lock from the background.

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
wl.acquire();

that is to gain it, and then to release it:

wl.release();

And of course, you would want to declare wl within the class body outside of any methods.

Reed
  • 14,703
  • 8
  • 66
  • 110
  • PowerManager.FULL_WAKE_LOCK is deprecated now, what should I use instead? – Behzad Mar 02 '13 at 18:06
  • See http://developer.android.com/reference/android/os/PowerManager.html#FULL_WAKE_LOCK – Reed Mar 22 '13 at 14:52
  • Thanks for answer. I've seen this link before, as you see it says that WakeLock was deprecated in API 17 and we should use FLAG_KEEP_SCREEN_ON, but it doesn't work correctly. When I use that flag, it doesn't turn the device on and the app can't start. Is that a big problem if we use a deprecated method or property in our app? – Behzad Mar 22 '13 at 16:19
  • I'd say you should be okay to use `FULL_WAKE_LOCK` at least for the next few updates of Android. API 17 is 4.2 if I'm not mistaken, which is on an extremely slim number of devices. Additionally, deprecated methods usually still function in updated version of Android (in my experience, anyway). – Reed Mar 22 '13 at 18:41
  • Also, if you want to avoid using a deprecated method, you could acquire a partial wake lock along with using [ACQUIRE_CAUSES_WAKEUP](http://developer.android.com/reference/android/os/PowerManager.html#ACQUIRE_CAUSES_WAKEUP) to wake up the device and turn the screen on. Not sure how efficient this would be compared to using the deprecated FULL_WAKE_LOCK – Reed Mar 22 '13 at 18:46
  • Thanks again. As the document's said, ACQUIRE_CAUSES_WAKEUP cannot be used with PARTIAL_WAKE_LOCK, but thank you very much for sharing your experience about deprecated methods. I've tested some ways, but if you need to wake the device up and bright the screen then showing an activity, the FULL_WAKE_LOCK and two other parameters is the only way works that I know! – Behzad Mar 22 '13 at 23:27