ADB shell 命令在应用程序中不起作用
ADB shell command not working from application
我正在创建一个禁用应用程序(包)的 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);
}
有什么办法可以看到执行代码的结果吗?
这对我有用:
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");
}
您忘记在第一个命令的末尾添加 \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);
}
我正在创建一个禁用应用程序(包)的 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);
}
有什么办法可以看到执行代码的结果吗?
这对我有用:
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");
}
您忘记在第一个命令的末尾添加 \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);
}