1

这个问题可能是重复的,但我已经浏览了所有答案并注意到它们将不再起作用。

 private static boolean checkRootMethod1() {
    String buildTags = android.os.Build.TAGS;
    return buildTags != null && buildTags.contains("test-keys");
}

方法 1 失败

 private static boolean checkRootMethod2() {
    String[] paths = { "/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
            "/system/bin/failsafe/su", "/data/local/su" };
    for (String path : paths) {
        if (new File(path).exists()) return true;
    }
    return false;
}

方法 2 也失败了,因为“SuperSu”不再是系统应用程序,它可以被卸载并且 su 文件现在存在于单独的文件夹 SU/bin/su

private static boolean checkRootMethod3() {
    Process process = null;
    try {
        process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        if (in.readLine() != null) return true;
        return false;
    } catch (Throwable t) {
        return false;
    } finally {
        if (process != null) process.destroy();
    }
}

方法 3 也失败了,因为现在 android 设备上没有“which”文件

RootTools.isavailable();

也失败了

我的问题是我可以通过检查 su 文件是否在 Su/bin/su 文件夹中来检测设备 root 吗?这是检测有根设备的正确方法吗?

4

1 回答 1

1
  1. 将“/su/bin/su”添加到 checkRootMethod2() 的路径变量
  2. 至于方法3,你也应该使用“/system/bin/which”来调用“which”
于 2016-04-20T13:44:35.157 回答