Reputation: 1818
I am creating an Android App (Xposed module) that disables applications (packages). When I run the command from adb shell
it runs perfectly. But from my application I am not able to figure out why it is not working.
Here is the code:
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);
}
Is there any way I can see the result of the executed code?
Upvotes: 1
Views: 1723
Reputation: 1239
You forgot to add \n
at the end of your first command.
Try with this:
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);
}
Upvotes: 0
Reputation: 1818
This worked for me:
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");
}
Upvotes: 3