首页 > 系统 > Android > 正文

Android 判断手机是否root

2019-11-09 15:29:24
字体:
来源:转载
供稿:网友
//判断手机是否rootpublic static boolean isRoot() { String binPath = "/system/bin/su"; String xBinPath = "/system/xbin/su"; if (new File(binPath).exists() && isCanExecute(binPath)) { return true; } if (new File(xBinPath).exists() && isCanExecute(xBinPath)) { return true; } return false;}PRivate static boolean isCanExecute(String filePath) { java.lang.Process process = null; try { process = Runtime.getRuntime().exec("ls -l " + filePath); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); String str = in.readLine(); if (str != null && str.length() >= 4) { char flag = str.charAt(3); if (flag == 's' || flag == 'x') return true; } } catch (IOException e) { e.printStackTrace(); } finally { if (process != null) { process.destroy(); } } return false;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表