Android 判断手机是否已经ROOT

来源:互联网 发布:教育机构域名注册 编辑:程序博客网 时间:2024/04/20 01:30
/**
  * 判断手机是否已经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;
 }
原创粉丝点击