4

Is there any way to quickly toggle the screen off without making Android sleep?

For example, I sometimes like to use the Calm app when I sleep. But it keeps the screen on all the time. When I just use that app for 10 minutes, it's great that it keeps the screen on; but if I'm sleeping for hours, I would like the app to keep on running (playing sounds) and turn the screen off.

How can this be done?

  • 3
    For this the app needs to explicitly create a so-called "Wakelock" that prevents Android to set the CPU into Deep Sleep and keeps the whole system (including your app) running. – GiantTree Aug 19 '15 at 20:12
  • @GiantTree Right. Is there a way to quickly toggle that on/off for all apps or a specific app? – RockPaperLizard Aug 19 '15 at 21:04
  • AFAIK an app has to ask for such a wakelock on its own. Otherwise Android may just kill an app if it is running in the background without a lock. – GiantTree Aug 19 '15 at 21:52
  • 1
    Changing /sys/class/leds/lcd-backlight/brightness to 0 does the job in my device. It doesn't put the device to sleep, but simply turn off the LEDs. Tested on that Calm app. You can hear its music yet not burning up the battery on screen. Requires root access though. – Firelord Aug 20 '15 at 10:02
  • 1
    Press the power button two times with gap of one second, the screen would come back to normal. I tried it over ADB so I could always change the value. You may bind this behavior to a button using Xposed Additions. Or perhaps a time based event in Tasker could also be an option. – Firelord Aug 20 '15 at 10:53
5

Credit goes to Firelord for the basic method. Here is a time-delay shell script that turns off the backlight for my device, and apparently others' as well.

Create a file named "lcdoff" and copy the following into it:

#!/system/bin/sh
if [ -z "$1" ]; then
    echo "usage: `basename $0` delay"
    exit
fi
su -c 'echo getsu > /dev/null'
echo "Tap power button 2x quickly to restore"
sleep $1
su -c 'echo 0 > /sys/class/leds/lcd-backlight/brightness'

Make sure:

  • The device is rooted.
  • The script permissions are set to executable, e.g. by chmod 755 lcdoff.
  • The script is located in /system/bin (scripts cannot be executed from /storage).

Then open a terminal app and enter lcdoff 10, to turn off the screen after a 10-second delay, lcdoff 30 for a 30-second delay, etc. To ensure that the processor stays on, simply enable the Android developer option "Stay Awake". Edit: Stay Awake only works while plugged into a power source -- see this answer for an alternative.

If you don't want to type the command in a terminal, you can launch the script as a custom action in:

  • Total Commander
  • Tasker
  • Xposed Additions
  • your app of choice
  • 1
    To avoid bumping my answer again, I'll add here the standby script I use: if [ "$1" == "0" ]; then su -c 'echo sbylock >/sys/power/wake_unlock'; elif [ "$1" == "1" ]; then su -c 'echo sbylock >/sys/power/wake_lock'; lcdoff 0; else echo "usage: $(basename $0) 0|1"; fi – user140691 Mar 21 '16 at 14:30
1

I had some trouble with the accepted answer as I'm not hugely familiar with shell scripting on Android/Unix/Linux so I thought I'd add my experience here for anyone in a similar boat.

To get this working with Tasker or similar the line you need is:

echo 0 > /sys/class/leds/lcd-backlight/brightness

For tasker put this in the 'command' field with 'Use Root' enabled, works like a charm. To disable simply switch the zero out for a 1, ergo:

echo 1 > /sys/class/leds/lcd-backlight/brightness

or lock and unlock the device.

So to answer your question about quickly toggling this behavior. Assign each of the above commands to a tasker task, then you can make use of the new long-press intercept in the latest tasker version to toggle the screen on and off without putting the device to sleep. Alternatively you can assign the command to a profile which triggers when your conditions are met.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.