0

我正在尝试使用 adb input text 方法将文本输入到当前正在运行的应用程序(不是我自己的)中,如果我从命令提示符运行它,例如'adb input text "Android",并且如果我运行它从终端模拟器。然而,下面的代码运行成功,但在屏幕上没有输出。我还尝试了各种其他方法来运行 shell 命令,这些命令也没有失败,但没有输出任何文本。有人知道我做错了什么吗?

try {
            //Runtime.getRuntime().exec("su");
            Runtime.getRuntime().exec("input text \":\"");
        } catch (IOException e) {
            e.printStackTrace();
        } 
4

3 回答 3

1

要将文本注入到 android 应用程序中,注入器必须具有

   android.permission.INJECT_EVENTS 

权限,所以它必须是系统应用程序。

您的 Runtime.getRuntime().exec 没有此权限。

于 2013-01-14T17:03:31.173 回答
0

如果您从本机可执行文件运行命令,它工作正常。构建 NDK 二进制文件并执行:

char * command = "input text hello%sworld\0";
system( command );//fork and exec input text ...
于 2015-07-13T11:36:11.523 回答
0

也许你需要使用: Runtime.getRuntime().exec("shell input text");

于 2019-02-19T23:05:22.117 回答