首页 > 解决方案 > 以编程方式运行 adb 命令 Android

问题描述

在运行测试用例之前,我试图在 Android 中以编程方式运行 adb 命令。但我得到以下异常

runShellCommand exception - Error running exec(). Command: [adb, shell, settings, put, secure, immersive_mode_confirmations, confirmed] Working Directory: null Environment: null

  private void runShellCommand(String command) {
        Timber.d("runShellCommand");
        try {
            Process process = Runtime.getRuntime().exec(command);
            process.waitFor();
        } catch (IOException | InterruptedException e) {
            Timber.d("runShellCommand exception - " + e.getMessage());
            e.printStackTrace();
        }
    }

这就是我使用 adb 命令调用该函数的方式

runShellCommand("adb shell settings put secure immersive_mode_confirmations confirmed");

有关如何解决此问题的任何建议,请

谢谢R

标签: javaandroidandroid-studioadb

解决方案


推荐阅读