您的位置:首页 > 移动开发 > Android开发

Android 判断手机是否root

2017-11-15 12:08 288 查看
//判断手机是否root

public static boolean isRoot() {

    String binPath = "/system/bin/su";

    String xBinPath = "/system/xbin/su";

 

    if (new File(binPath).exists() && isCanExecute(binPath)) {

        return true;

    }

    if (new File(xBinPath).exists() && isCanExecute(xBinPath)) {

        return true;

    }

    return false;

}

 

private static boolean isCanExecute(String filePath) {

    java.lang.Process process = null;

    try {

        process = Runtime.getRuntime().exec("ls -l " + filePath);

        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));

        String str = in.readLine();

        if (str != null && str.length() >= 4) {

            char flag = str.charAt(3);

            if (flag == 's' || flag == 'x')

                return true;

        }

    } catch (IOException e) {

        e.printStackTrace();

    } finally {

        if (process != null) {

            process.destroy();

        }

    }

    return false;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: