如何从 Java 在 Android 设备上运行 adb screenrecord 并结束屏幕录制?

ALM*_*ALM 3 java multithreading android adb threadpoolexecutor

如何adb shell screenrecordAndroid设备上运行Java和结束screenrecording

目前我必须指定--time-limit结束录音。如果我尝试在视频结束之前捕获视频,则会失败。

有没有办法告诉 adb 停止录制?是否存在一种配置线程发送方式CTRL-Cshell命令?

这将在无根电话上运行。

代码

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();
  }

      });
Run Code Online (Sandbox Code Playgroud)

Ale*_* P. 5

无论是发送SIGINT还是SIGHUPscreenrecord过程会导致它停止录制。

我只是在 2 个单独的adb shell会话中在无根(库存 Android 6.0)手机上尝试了以下操作:

在会话 #1 中:

screenrecord /sdcard/Movies/test.mpg
Run Code Online (Sandbox Code Playgroud)

在第 2 节中:

pkill -INT screenrecord
Run Code Online (Sandbox Code Playgroud)

screenrecord发出后捕获停止pkill命令