如何从Java在Android设备上运行adb screenrecord并结束屏幕记录?
如何从Java
在Android
设备上运行adb shell screenrecord
并结束screenrecording
?
目前我必须指定--time-limit
来结束录制。 如果我尝试在结束之前捕获video,则失败。
有没有办法让adb停止录音? 有没有办法配置线程将CTRL-C
发送到shell
命令?
这将在无根电话上运行。
码
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(); } });
向screenrecord
记录过程发送SIGINT
或SIGHUP
会导致它停止录制。
我刚刚在2个单独的adb shell
会话中尝试了以下针对无根(Android 6.0手机)的手机:
在会议#1中:
screenrecord /sdcard/Movies/test.mpg
在会议#2中:
pkill -INT screenrecord
并且在发出pkill
命令后停止了screenrecord
捕获