【问题标题】:Can't execute pm install in program无法在程序中执行 pm install
【发布时间】:2013-10-01 10:44:31
【问题描述】:

我有一个必须使用 pm install 的 android 程序,它是一个企业应用程序,我想运行 pm install 为我们的客户静默更新应用程序

我有一个方法可以运行 pm install 但什么也没发生,我不明白为什么?有人可以帮助我吗?

private void installproperlyApp(){
        Process process = null;
        try{
            process = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(process.getOutputStream());
            System.out.println("DANS LE INSTALL COMMAND");
            os.writeBytes("pm install -r /sdcard/telegestion.apk"+"\n");

            os.writeBytes("exit\n");
            os.flush();
            os.close();

            String line ="";
            //on récupère l'inputStream sinon on a un deadLock pour le process
            BufferedReader inputProcess = new BufferedReader(new InputStreamReader(process.getInputStream()));
            while ((line = inputProcess.readLine()) != null) {
                System.out.println(line);
            }

            //on récupère l'errorStream sinon on a un deadLock pour le process
            BufferedReader errorProcess = new BufferedReader(new InputStreamReader(process.getErrorStream()));
            while ((line = errorProcess.readLine()) != null) {
                System.out.println(line);
            }
            //process.waitFor();

        } catch (IOException e) {
            System.out.println(e.toString());
        } finally {
            if (process != null)
                process.destroy();
        }
    }

【问题讨论】:

  • Bienvenue sur Stack,倒是个首映式问题,elle est bien posée,bonne continuation!
  • 您的代码解决了我的问题。谢谢。

标签: android process


【解决方案1】:

我设法运行了我的 pm 命令。 是 SuperSU 阻止了我在 root 访问权限下执行的子进程。 在 SuperSu 中,您在参数部分有一个信任子进程的参数。 正是那个默认为 false 的参数阻止了我的 pm 命令。设置为 true 就没有问题了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    • 2020-10-12
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-24
    相关资源
    最近更新 更多