android 判断app是否具有root权限

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qwertyuiop159158/article/details/52900194

    应用判断是否具有root权限,只需要看能否在data分区创建文件,如果能够在data分区创建文件,那么应用具有root权限


public static boolean upgradeRootPermission( ) {  
   Process process = null;  
   DataOutputStream os = null;  
   try {  

    Log.i("roottest", "try it");
    String cmd = "touch /data/roottest.txt";
       process = Runtime.getRuntime().exec("su"); //切换到root帐号  
       os = new DataOutputStream(process.getOutputStream());  
       os.writeBytes(cmd + "\n");  
       os.writeBytes("exit\n");  
       os.flush();  
       process.waitFor();  
   } catch (Exception e) {  
       return false;  
   } finally {  
       try {  
           if (os != null) {  
               os.close();  
           }  
           process.destroy();  
       } catch (Exception e) {  
       }  
   }  
   return true;  
}

猜你喜欢

转载自blog.csdn.net/qwertyuiop159158/article/details/52900194