Is there a way to lock the Android screen via the ADB?
I find ways to lock the display in an apk, but I want to lock the screen from the PC via ADB, to simulate a display timeout, without having to wait for the timeout.
Is it possible to do this?
Thanks, Diane
Find and tap Settings > Lock screen & security > Screen lock > Password. Enter a screen lock password (at least 4 characters), then tap NEXT. Re-enter the password, then tap CONFIRM.
If "Smart Lock" is active and "Power button instantly locks" is set, then you can manually lock the screen by tapping the "lock icon" on the bottom of the lock screen. Show activity on this post. 2) Press the device power button twice in quick succession.
Cool, I just found KEYCODE_POWER
which is 26.
so it works by sending:
adb shell input keyevent 26
which locks the screen if the screen is unlocked. If the screen is already locked, it wakes up the device.
My guess is that the only way to ensure that the screen is locked (off), is to unlock (we use keyevent 82 (menu), then lock it with the power button keyevent. Does anyone have any idea if this is true?
Michael R. Hines gave the what is arguably the easiest solution. However, the following line is not useful in later versions of Android.
adb shell input keyevent 82 # unlock
I've updated the shell script using coordinates for the individual device I want to wake (Tablet). My tablet does not support orientation changes for lockscreen events, so the values always work as the lockscreen is always in landscape. Should you require orientation change detection, a simple if/then/else would suffice in picking the correct coordinates to use for the orientation.
#!/bin/bash if [ "$(adb shell dumpsys power | grep mScreenOn= | grep -oE '(true|false)')" == false ] ; then echo "Screen is off. Turning on." adb shell input keyevent 26 # wakeup adb shell input touchscreen swipe 930 380 1080 380 # unlock echo "OK, should be on now." else echo "Screen is already on." echo "Turning off." adb shell input keyevent 26 # sleep fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With