美文网首页
用 adb 判断屏幕是否唤醒

用 adb 判断屏幕是否唤醒

作者: demil | 来源:发表于2016-08-11 11:53 被阅读2164次
遇到问题
  • 在Jenkins定时跑Appium时,屏幕休眠状态时,应用不能启动
解决方法
  • 在构建的时候先判断下屏幕是否休眠,如果不休眠,则唤醒屏幕
    • 判断屏幕是否休眠
  /** * 判断设备是否休眠 
  * @return 
  * @throws IOException 
  */
  public boolean isScreenLock() throws IOException {
            Runtime rt = Runtime.getRuntime(); 
            Process p = rt.exec("cmd.exe /c adb shell dumpsys power | findstr \"Display Power:state=\""); 
            BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); 
            String line; 
            String content = ""; 
            boolean flag = false; 
            while ((line = in.readLine()) != null)
            content = content + line; 
            if (content.contains("Display Power: state=OFF"))
                    flag = true;
            p.destroy();
            return flag;
  }
  • 唤醒屏幕
  if(getUrlFile.isScreenLock()){
        // 模拟Power键 
        Runtime.getRuntime().exec("adb shell input keyevent 26");
       // 模拟Home键
        Runtime.getRuntime().exec("adb shell input keyevent 3");
}

相关文章

网友评论

      本文标题:用 adb 判断屏幕是否唤醒

      本文链接:https://www.haomeiwen.com/subject/hkxssttx.html