2013-10-01 74 views
2

我有必须使用时安装的Android程序,这是一个企业应用程序,我想运行时安装客户默默地更新应用无法执行时安装程序

我有一个方法这可能会运行下午安装但没有发生,我不明白为什么?有人可以帮助我吗?

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(); 
     } 
    } 
+0

Bienvenue sur Stack,首次提出的问题,elle est bienposée,bonne continuation! –

+0

你的代码解决了我的问题。谢谢。 – Aldridge1991

回答

1

我设法运行我的pm命令。 这是SuperSU阻止我的子进程在root acces下执行。 在SuperSu中,您在参数部分有一个用于信任子过程的参数。 这是默认为false的参数,它阻止了我的pm命令。设置为真,没有问题了。

相关问题