最近需要禁止root手机运行app,需要判断手机是否root,如果root可以弹框提示风险,也可以闪退,本文采用的方式是闪退
废话不多说贴代码
//遍历检测su是否存在
private boolean CheckRootPathSU() {
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()) {
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
//常规检测su是否存在
private boolean checkRootWhichSU() {
String[] strCmd = new String[]{"/system/xbin/which", "su"};
ArrayList<String> execResult = executeCommand(strC