判断Android手机是否已root的方法

/**
 * 是否存在su命令,并且有执行权限
 *
 * @return 存在su命令,并且有执行权限返回true
 */
public static boolean isSuEnable() {
    File file = null;
    String[] paths = {"/system/bin/", "/system/xbin/", "/system/sbin/", "/sbin/", "/vendor/bin/", "/su/bin/"};
    try {
        for (String path : paths) {
            file = new File(path + "su");
            if (file.exists() && file.canExecute()) {
                Log.i(TAG, "find su in : " + path);
                return true;
            }
        }
    } catch (Exception x) {
        x.printStackTrace();
    }
    return false;
}

 

你可能感兴趣的:(Android相关)