ADB shell command not working from application

1.6k views Asked by At

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?

2

There are 2 answers

0
Himanshu Jain On BEST ANSWER

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");
             }
0
Bruno Parmentier On

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