Android 判断手机是否已经ROOT

/**
  * 判断手机是否已经ROOT
  * @return 手机是否已经ROOT
  * @throws IOException
  * @throws InterruptedException
  */
 public static boolean hasRooted() throws IOException, InterruptedException{
  Process process = null;
     DataOutputStream out = null;
  try {
   process =  Runtime.getRuntime().exec("su");
   out = new DataOutputStream(process.getOutputStream());
   out.writeBytes("\n");
   out.writeBytes("exit\n");
   out.flush();
   process.waitFor();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   Log.d("Test", "Unexpected error - Here is what I know: "+e.getMessage());
   return false;
  } finally {   
   try {   
    if (out != null)
     out.close();      
    process.destroy();   
    } catch (Exception e) {   
        e.printStackTrace();  
      }   
    }   
   return true;
 }

你可能感兴趣的:(Android 判断手机是否已经ROOT)