Connect your device via ADB to a PC (google it if you don't know how) and run the command "adb tcpip 5555". That's it, you can disconnect your device now.
Then in Tasker, create an action with this plugin and type in the following:
IP Address: localhost
ADB Shell Command: input keyevent POWER
Hit the play button to test this action. If you've done everything right, your screen will turn off.
Congrats, you just executed a command on an unrooted device which usually requires root privileges!
The only downside is, the tcpip setting does not survive a reboot, so you have to set the port 5555 again via PC after rebooting the device.
I hope I explained the important part well enough. If that's not the case, don't hesitate to quote me and I'll answer here.
Hello both of you. I know this is a relatively old thread but I do hope this reaches either of you.
The power button on my Mi A1 recently stopped working and I have been surfing through XDA to figure out a way to simulate the power button using a screen gesture (eg: double tap on a certain area on the homescreen). Almost 3 articles led me to this thread and I tried the steps mentioned in the quoted comment, but to no avail. 'adb devices' recognises the device and I can even successfully execute 'adb tcpip 5555'. The remaining steps seem straight-forward too but yield no output (I have tried different . Surprisingly, typing 'input keyevent POWER' or 'input keyevent 26' both don't yield any result through the adb command prompt on PC too (with USB or WiFi), so I can't say for sure where the problem lies.
This is what the the adb power shell shows:
input : The term 'input' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ input keyevent POWER
+ CategoryInfo : ObjectNotFound: (input:String) , CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I'm running on Android Pie (1st July 2019 security patch) with the latest version of both Tasker as well as this plugin. Is this something that has stopped working Pie onwards or something? Is there a different way to emulate the power key to turn off the screen without having to use the pin to unlock the device (I use the fingerprint scanner to unlock)?
I'll be frank, I'm having to do this for the very first time, so if I've made a rookie mistake, do point out
Edit: Rookie mistake found myself 🤦🏻*♂️. 'adb shell input keyevent POWER' does execute the event via the command prompt. However, while 'adb tcpip 5555' does restart in TCP mode:5555, even 'adb devices' won't recognise the device after I have disconnected it from the USB. Isn't it suppose to work over WiFi?
Good you found out how adb shell works! From a pc normally you type "adb shell" and enter to enter the shell and then you can send commands like "input keyevent POWER". (And you can exit with typing "exit" or pressing Ctrl+C). "adb shell YOUR_COMMAND" is just shorthand to enter shell, send the command and exit it again.
If you turn on adb over wifi with "adb tcpip 5555" and plug out the cable you need to still connect your pc to your device. In this case you type "adb connect THE_IP_OF_YOUR_PHONE:5555" and then you can adb shell however you like.
Adb plug-in does this last thing automatically, so it connects to the device using "adb connect", it enters the shell using "adb shell" and then it sends your command. After your given timeout in ms, it closes the connecting and disconnects from the device over adb.
This means that if you did your tcpip command, adb over wifi should be enabled on your device and you should be able to use adbplugin using "localhost" as IP and "5555" as port.
Thanks for explaining what was happening there. Unfortunately, it still didn't change the fact that I couldn't run the command locally from the phone. But, I just got pointed to the fact that Tasker now has an in-built 'Turn Off' task under Action Category > Display that does exactly what I wanted—lock the screen while still allowing me to unlock using the FPS—albeit using a task shortcut instead of a portion of the screen. It also does so in a single tap, but given that we are so used to expecting a double tap for this, I replaced a 'If/Else/End If' tutorial to make a multi-tap button, to make a single tap output a Flash message to say "Tap again to lock" and a double tap to lock the screen. Ergo, mission accomplished .
I'm weirdly happy that my power button broke. It made me learn something I had absolutely no idea about. It's just another reason to love Android. Even without root, it's crazy what one can do on Android. Thanks for your prompt response and kudos on the plugin
|Thread Tools||Search this Thread|