How to lock Android screen via ADB?

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

    For those using earlier versions of android (4.2+ at least), dumpsys power has a different output.
    Instead of using mPowerState= as the answer given by @Jakub Czaplicki, I used mScreenOn=.

    p = Runtime.getRuntime().exec("su", null, null);
    OutputStream o = p.getOutputStream();
    o.write(("dumpsys power").getBytes("ASCII"));
    o.flush();
    o.close();
    p.waitFor();
    
    boolean screenState;
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while ((res = in.readLine()) != null) dump += res;
    screenState = dump.charAt( dump.indexOf("mScreenOn=") + 10 ) == 't';
    

    screenState is true (screen on), or false (screen off).

提交回复
热议问题