2013-02-25 69 views

回答

4

我使用RootTools圖書館做禁用/啓用命令

CommandCapture command_enable = new CommandCapture(0,"pm enable "+ Package_Name);       
RootTools.getShell(true).add(command_enable).waitForFinish(); 

CommandCapture command_disable = new CommandCapture(0,"pm disable "+ Package_Name); 
RootTools.getShell(true).add(command_disable).waitForFinish(); 
+0

你知道,如果還有檢查它是否是「凍結」的方法嗎? – NoBugs 2013-06-28 03:11:50

+0

爲什麼使用'CommandCapture'時,它是'Command'的擴展名,用於保存輸出? http://code.google.com/p/roottools/source/browse/trunk/Developmental/RootTools_sdk3_generic/src/com/stericson/RootTools/Command.java?r=208 – NoBugs 2013-06-28 03:16:38

1

您實際上可以嘗試運行root命令並捕獲響應並確定該設備是否已生根。

here以代碼並修改它一點點地滿足您的需求,我認爲這可能是這樣的:

public static boolean canRunRootCommands() 
     { 
      boolean retval = false; 
      Process suProcess; 

      try 
      { 
      suProcess = Runtime.getRuntime().exec("su"); 

      DataOutputStream os = new DataOutputStream(suProcess.getOutputStream()); 
      DataInputStream osRes = new DataInputStream(suProcess.getInputStream()); 

      if (null != os && null != osRes) 
      { 
       retval = true; 

       /* 
       *if got to this point, its safe to assume the 
       *device is rooted and here you can do something 
       *to tell your app that su is present. Or you could 
       *use the bool return of this function to know that the 
       *device is rooted and make the app act different. 
       */ 

      } 
      } 
      catch (Exception e) 
      { 
      // Can't get root ! 
      // [...] meaning that the device is not rooted 

      retval = false; 
      } 

      return retval; 
     } 

我沒有測試過這一點,但我敢肯定,它會幫助你。或者至少它會以正確的方式指出你。

相關問題