1

我正在创建一个禁用应用程序(包)的 Android 应用程序(Xposed 模块)。当我从中运行命令时,adb shell它运行完美。但是从我的应用程序中,我无法弄清楚它为什么不起作用。

这是代码:

try {
    Process su = Runtime.getRuntime().exec("su");
    DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
    outputStream.writeBytes("pm disable com.bt.bms");

    outputStream.writeBytes("exit\n");
    outputStream.flush();
}
catch (IOException e) {
    throw new RuntimeException(e);
}

有什么办法可以看到执行代码的结果吗?

4

2 回答 2

3

这对我有用:

               try {
                 Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "pm disable com.bt.bms" });
                 proc.waitFor();
             } catch (Exception ex) {
                 XposedBridge.log("Could not reboot");
             }
于 2015-08-20T02:58:49.490 回答
0

您忘记\n在第一个命令的末尾添加。

试试这个:

try {
    Process su = Runtime.getRuntime().exec("su");
    DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

    outputStream.writeBytes("pm disable com.bt.bms\n");
    outputStream.flush();

    outputStream.writeBytes("exit\n");
    outputStream.flush();
} catch (IOException e) {
    throw new RuntimeException(e);
}
于 2015-08-20T13:11:36.903 回答