解决方案 »

  1.   

    用下面方法
     // 判断机器Android是否已经root,即是否获取root权限
        protected static boolean haveRoot() {
     
            int i = execRootCmdSilent("echo test"); // 通过执行测试命令来检测
            if (i != -1) {
                return true;
            }
            return false;
        }
      

  2.   

    我想判断在请求Root时,用户点了允许还是拒绝
      

  3.   


    你这 execRootCmdSilent都不提供,楼主肯定没办法的,直接执行su就行了
      

  4.   


    你这 execRootCmdSilent都不提供,楼主肯定没办法的,直接执行su就行了不好意思,忘记了,补上
     protected static int execRootCmdSilent(String paramString) {
            try {
                Process localProcess = Runtime.getRuntime().exec("su");
                Object localObject = localProcess.getOutputStream();
                DataOutputStream localDataOutputStream = new DataOutputStream(
                        (OutputStream) localObject);
                String str = String.valueOf(paramString);
                localObject = str + "\n";
                localDataOutputStream.writeBytes((String) localObject);
                localDataOutputStream.flush();
                localDataOutputStream.writeBytes("exit\n");
                localDataOutputStream.flush();
                localProcess.waitFor();
                int result = localProcess.exitValue();
                return (Integer) result;
            } catch (Exception localException) {
                localException.printStackTrace();
                return -1;
            }
        }
      

  5.   

    localProcess.waitFor(); 这句在某些手机如,酷派4.4上会停滞没有反应,判断失败!
      

  6.   

    private final static int kSystemRootStateUnknow=-1;
        private final static int kSystemRootStateDisable=0;
        private final static int kSystemRootStateEnable=1;
        private static int systemRootState=kSystemRootStateUnknow;
       
        public static boolean isRootSystem()
        {
         if(systemRootState==kSystemRootStateEnable)
         {
          return true;
         }
         else if(systemRootState==kSystemRootStateDisable)
         {      return false;
         }
      File f=null;
      final String kSuSearchPaths[]={"/system/bin/","/system/xbin/","/system/sbin/","/sbin/","/vendor/bin/"};
      try{
      for(int i=0;i<kSuSearchPaths.length;i++)
      {
       f=new File(kSuSearchPaths[i]+"su");
       if(f!=null&&f.exists())
       {
        systemRootState=kSystemRootStateEnable;
        return true;
       }
      }
      }catch(Exception e)
      {
      }
      systemRootState=kSystemRootStateDisable;
      return false;
        }通过su文件是否存在来判断