Команда ADB shell не работает из приложения
Я создаю приложение для 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);
}
Есть ли способ увидеть результат выполненного кода?
2 ответа
Решение
Это сработало для меня:
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);
}