2012-11-19 19 views
5

アンドロイドデバイスがルートされているかどうかを確認するにはどうすればよいですか?私は次のコードを使用しています:アンドロイドデバイスがルーツデバイスであることを確認するにはどうすればよいですか?

Process proc = Runtime.getRuntime().exec ("su"); 

そして、私は次の例外を持っています。

Causes by:Permission denied 

しかし、エミュレータで実行しても例外はありません。

私は別の方法で確認しています。エミュレータのために称賛ラインでadb shellを入力すると、#を返しますが、デバイスがadb shellを書くために、次のエラーを与える:デバイスが根ざしされているかどうか

[email protected]:/ $ su 
su 
/system/bin/sh: su: not found 
127|[email protected]:/ $ 

は、どのように私がチェックすることができます。

ありがとうございました。

答えて

4

私はこのクラスを使用します。

private void CheckRoot() 
    {      
     Process p; 

     try { 
       // Preform su to get root privledges 
       p = Runtime.getRuntime().exec("su"); 

       // Attempt to write a file to a root-only 
       DataOutputStream os = new DataOutputStream(p.getOutputStream()); 
       os.writeBytes("echo \"Do I have root?\" >/data/LandeRootCheck.txt\n"); 

       // Close the terminal 
       os.writeBytes("exit\n"); 
       os.flush(); 
       try { 
        p.waitFor(); 
         if (p.exitValue() == 0) { 
          // TODO Code to run on success       
         this.IsRoot=true; 
         } 
         else { 
          // TODO Code to run on unsuccessful 
          this.IsRoot=false; 
         } 
       } catch (InterruptedException e) { 
        // TODO Code to run in interrupted exception 
        toastMessage("not root"); 
       } 
      } catch (IOException e) { 
       // TODO Code to run in input/output exception 
       toastMessage("not root"); 
      } 
    } 
関連する問題