【问题标题】:How can check android Device is Rooted Device? [duplicate]如何检查 android 设备是 Rooted 设备? [复制]
【发布时间】:2012-11-19 06:24:41
【问题描述】:

如何检查安卓设备是否已root?我正在使用以下代码:

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

当我在设备上运行它时,出现以下异常。

Causes by:Permission denied

但是在模拟器上运行并没有任何异常。

我正在使用另一种方式进行检查。在模拟器的命令行输入 adb shell 会返回 #,但对于设备写入 adb shell 会出现以下错误:

shell@android:/ $ su  
su   
/system/bin/sh: su: not found   
127|shell@android:/ $  

那么如何检查设备是否已root。

提前致谢。

【问题讨论】:

    标签: android adb


    【解决方案1】:

    我使用这个类:

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

    【讨论】:

      猜你喜欢
      • 2012-10-25
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 2012-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多