Reputation: 4410
Could someone show me in a snipet of code how to set the backlight always on in android ?
Upvotes: 0
Views: 3611
Reputation: 4598
As an alternative to WakeLock, I'd suggest using the FLAG_KEEP_SCREEN_ON flag.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
This is easier to use than WakeLock, as you don't need to worry about releasing it when the activity is paused/destroyed.
Window flag: as long as this window is visible to the user, keep the device's screen turned on and bright.
Upvotes: 5
Reputation: 20946
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK , "My Tag");
wl.acquire();
// ..screen will stay on during this section..
wl.release();
Nb. the keyboard backlight will be allowed to go off.
Upvotes: 0