2013-02-25 6 views

Répondre

4

J'utilise la bibliothèque de RootTools faire activer/désactiver la commande

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

Savez-vous s'il y a aussi un moyen de vérifier si elle est « gelé »? – NoBugs

+0

Pourquoi utiliser 'CommandCapture', quand c'est une extension de' Command' destinée à contenir la sortie? http://code.google.com/p/roottools/source/browse/trunk/Developmental/RootTools_sdk3_generic/src/com/stericson/RootTools/Command.java?r=208 – NoBugs

1

Vous pourriez réellement essayer d'exécuter une commande de racine et attraper la réponse et déterminer si le périphérique est enraciné.

Prendre le code de here et de modifier un peu pour répondre à vos besoins, je pense qu'il pourrait se présenter comme suit:

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; 
     } 

Je n'ai pas testé mais je suis sûr que cela vous aidera. Ou au moins, cela vous indiquera la bonne voie.

Questions connexes