Introduction: Turning Android Screen on and Off Triggered by Its Charging State
It would be a great feature to turn on Android only when plugged in, if you intend to, say, put an old phone into work as a dedicated car GPS device.
In this approach, the Android device will be put into a low-power state which can last several days, then the turn-on of device after power is connection will become an automatic process. Notice that I am not trying to completely shut down or even suspend the phone, hoping to harvest from a bug and power it up. Thus, my approach is potentially effective on nearly every phone, including much older ones, and it also eliminates the time when waiting for the phone to boot up.
As a reference, here is the competing method if you want your Android device to completely boot up from off state: (I did not make this video, nor do I sponsor the method introduced in it)
- Android phone with charging cable
- 'Tasker' or a similar automation app
- 'Root Explorer' or 'Terminal Emulator' or a similar file system app
Step 1: Root Your Phone
By rooting your phone, you will lose its warranty.
Here are some general guidelines:
Or, you can search for the root method for your specific make and model.
Step 2: (Optional) Install ABS Tweaks to Clear RAM
The tool is leveraged to further minimize power consumption during the off state. ABS Tweaks, which used to be Arkaynine Boost Script, is developed by LordArcadius. By omitting this tool, you can still terminate processes and turn off screen to save battery.
However, the installation of ABS Tweaks takes a bit more effort, as it involves a customized Recovery. For precautions and the installation procedure, please follow the original thread:
Step 3: Enter Low-Power State When Out-of-Power
We will use the 'Tasker' app to accomplish this, and we also need to grant root access for the Tasker app. In the Tasker app, do the following:
- make a task to kill running apps and turn off the screen,
- write a profile to monitor battery charging status, and
- write a profile to perform the above task in the event of power loss with some delay, and provide a canceling feature when power is restored within seconds.
The relevant shell commands, to be executed in the task of Item #1 above, are shown as follows:
1) pkill com.;
It kills running apps, as the process name for most commercial apps starts with "com.";
It clears the RAM using the optional ABS Tweaks;
3) timeout -t 3 sh /system/bin/input keyevent 26;
It turns the screen off.
Finally, I am also attaching the Tasker profile script files, in which a notification is shown to alert the user of the upcoming screen off. You may either import this profile in the Tasker app, or refer to this example when writing your own.
Step 4: Wake From Low-Power State
This is simple. Just plug it in and the phone will automatically wake up by itself.
Of course, the phone will also wake up when you hit a button, but it will go back to sleep due to the Tasker mechanism when no external power source is connected.
Sometimes, to charge a deeply drained battery more quickly, you can turn off the phone to reduce its power consumption.
To revert the phone back to normal usage, simply remove the Tasker routine or the Tasker app, and optionally remove the ABS Tweaks if you prefer.