2013-10-01 73 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命令。設置爲真,沒有問題了。

相關問題