簡體   English   中英

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM