【问题标题】:Can any one tell me what is wrong with my code,everytime i run it i get the io exception error谁能告诉我我的代码有什么问题,每次我运行它我都会得到 io 异常错误
【发布时间】:2021-11-14 06:57:43
【问题描述】:

这是我的代码 基本上在手机中使用 adb 来卸载应用程序,但它目前无法正常工作,任何人都可以帮助我

       Process pro;
    StringBuilder output = new StringBuilder();
    try {
        pro = Runtime.getRuntime().exec(new String[]{"pm uninstall –k ––user 0 
        com.google.android.gm"});
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(pro.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            output.append(line).append(" ");
            pro.waitFor();
        }
    } catch (IOException | InterruptedException e) {
        e.printStackTrace();
    }
    String response = output.toString();
    System.out.println(response);
    Log.d("log", response);

这是我遇到的错误

     W/System.err: java.io.IOException: Cannot run program "pm uninstall –k ––user 0 
    com.google.android.gm": error=13, Permission denied
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
       W/System.err:     at java.lang.Runtime.exec(Runtime.java:698)
    at java.lang.Runtime.exec(Runtime.java:563)
    at com.example.adb.MainActivity.onCreate(MainActivity.java:23)

谁能解决这个问题。

【问题讨论】:

  • Runtime.getRuntime().exec() 中的 arg 正在使用的设备的 adb shell 上运行。据我所知。

标签: java android adb uninstallation


【解决方案1】:

我认为问题可能出在new String[]{"pm uninstall –k ––user 0 com.google.android.gm"}。尝试使用普通字符串而不是字符串数组。

【讨论】:

  • 我也尝试过,但这样做我没有得到任何响应代码,即使没有日志显示出来
【解决方案2】:

Runtime.exec() 需要带有命令名称和参数的 cmdarray

pro = Runtime.getRuntime().exec(new String[]{"pm", "uninstall", "–k", "––user", "0", "com.google.android.gm"});

【讨论】:

    猜你喜欢
    • 2017-10-09
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    • 2021-08-15
    • 2021-09-06
    • 1970-01-01
    • 2021-12-09
    相关资源
    最近更新 更多