小编Aru*_*ran的帖子

如何以编程方式找到有根设备?

在安装我的应用程序之前,我希望它检查设备是否已 root。我使用了以下代码

private static boolean isRooted()

                 return findBinary("su");
        }
    public static boolean findBinary(String binaryName) {

        boolean found = false;
        if (!found) {

            String[] places = {"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/",
                    "/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"};
            for (String where : places) {
                if ( new File( where + binaryName ).exists() ) {

                    found = true;
                    break;
                }
            }
        }
        return found;
    } 
Run Code Online (Sandbox Code Playgroud)

它工作正常。但我听说可以更改文件名“su”,并且可以在非根设备中创建名为“su”的文件。在这种情况下,此源不可靠。所以我想除了搜索“su”之外,还知道其他一些方法来找到有根设备。我使用了以下代码

   Public static boolean checkRootMethod1()

     {
        String buildTags = android.os.Build.TAGS;

        if (buildTags != null && buildTags.contains("test-keys")) {

            return true;
        }

        return …
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1