androidshellxposed-framework

ADB shell command not working from application


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?


Solution

  • 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");
                 }