如何在Java
中运行adb shell screenrecord
并结束screenrecording
?涉及到Android
设备和IT技术相关内容。
目前我必须指定--time-limit
来结束录制。如果在录制结束之前尝试捕获视频,则会失败。
有没有办法告诉adb停止录制?是否可以配置线程向shell
命令发送CTRL-C
?
这是要在未root的手机上运行。
代码:
videoExecutor.submit(() -> {
//Start recording video
String recordVideo = "screenrecord --time-limit " + testRun.getVideoLength() + " " + "/sdcard/" + logDate + ".mp4";
try {
device.executeShell(recordVideo);
} catch (Exception e1) {
e1.printStackTrace();
}
sleep(testRun.getVideoLength()*ONE_SECOND + TWO_SECONDS); //gotta match the --time-limit above.
RemoteFile remote = new RemoteFile("/sdcard/" + logDate + ".mp4");
File local = new File(videoPath); //Save file to local machine
if(!local.getParentFile().exists()) {
local.getParentFile().mkdirs();
}
try {
//Copy video from phone to computer
try {
device.pull(remote, local);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
pid
- 当尝试向在相同用户ID下运行的进程发送信号时,不应出现权限问题。 - Alex P.