Android设备根检查

时间:2018-10-31 12:01:58

标签: android root

我想检查我的设备是否已植根。当我在实际设备中尝试以下代码时,如果没有root,就可以了。但是非root用户的仿真器会在此行中断

if (new File(path).exists())
    return true;

“ / system / xbin / su”路径存在。

private static boolean isRooted() {
    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", "/su/bin/su"};
    for (String path : paths) {
        if (new File(path).exists())
            return true;
    }
    return false;
}

Genymotion或Android Studio的模拟器始终会在代码块中中断。

所有android模拟器都植根了吗?

1 个答案:

答案 0 :(得分:2)

您可以通过以下方法检查设备是否已植根:

 <NavLink
   className="tags"
   activeStyle={{ color: 'red' }}
   to={'/page'}
 >
   LINK
 </NavLink>

如果设备植根于其他public static boolean isRootedDevice(Context context) { boolean rootedDevice = false; String buildTags = android.os.Build.TAGS; if (buildTags != null && buildTags.contains("test-keys")) { Log.e("Root Detected", "1"); rootedDevice = true; } // check if /system/app/Superuser.apk is present try { File file = new File("/system/app/Superuser.apk"); if (file.exists()) { Log.e("Root Detected", "2"); rootedDevice = true; } } catch (Throwable e1) { //Ignore } //check if SU command is executable or not try { Runtime.getRuntime().exec("su"); Log.e("Root Detected", "3"); rootedDevice = true; } catch (IOException localIOException) { //Ignore } //check weather busy box application is installed String packageName = "stericson.busybox"; //Package for busy box app PackageManager pm = context.getPackageManager(); try { Log.e("Root Detected", "4"); pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); rootedDevice = true; } catch (PackageManager.NameNotFoundException e) { //App not installed } return rootedDevice; } ,它将返回true