How to lock Android screen via ADB?

后端 未结 8 902
长发绾君心
长发绾君心 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:45

    You can use following command to trigger display ON. adb shell input keyevent POWER

    I tried and am using in my project, Hope it will work for you.

    And here is the ruby code I used:

    def ScreenCheck()
    system("adb shell dumpsys power > c:/interact.log")
    
    File.open("C:\\interact.log").each do |line|
        if line[/mScreenOn/]
            if line.strip == "mScreenOn=true"
                p "Screen is On, Starting execution.."
            else
                p "Screen is Off, starting screen.."
                system("adb shell input keyevent = POWER")
                p "Starting execution.."
            end
        end
    end
    end
    

提交回复
热议问题