How to lock Android screen via ADB?

后端 未结 8 916
长发绾君心
长发绾君心 2021-01-30 03:20

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 displ

8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 03:50

    Here's the whole thing in one single bash script which checks if the screen is actually on or not and then wakes up and unlocks the screen in one shot:

    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 keyevent 82 # unlock
        echo "OK, should be on now."
    else 
        echo "Screen is already on."
    fi
    

提交回复
热议问题