How to check if android phone is rooted? [duplicat

2019-03-26 12:28发布

This question already has an answer here:

I want to programatically find in my application if the android phone is rooted. I found many links like: Determine if running on a rooted device Effective way to programatically check if I'm rooted on Android? discussing on the same topic. However, as mentioned in those links there is no one and definite way to find out. These posts are pretty old and I was wondering if there is anything better to achieve it now in recent releases?

Thanks in advance!

标签: android root
2条回答
Deceive 欺骗
2楼-- · 2019-03-26 13:08

You can use the roottools library. They offer a method to check for root access. https://code.google.com/p/roottools/

查看更多
\"骚年 ilove
3楼-- · 2019-03-26 13:14

I've wrapped this code (working ok without any other external jar/lib) from RootTools

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;
}
查看更多
登录 后发表回答