Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android根目录检查在samsung选项卡上执行时失败/system/bin/which su_Java_Android_Android Studio - Fatal编程技术网

Java Android根目录检查在samsung选项卡上执行时失败/system/bin/which su

Java Android根目录检查在samsung选项卡上执行时失败/system/bin/which su,java,android,android-studio,Java,Android,Android Studio,我已经跟踪了链接 检查应用程序是否在根安卓设备上运行。对于某些设备和模拟器来说,它工作正常,但对于我的新三星平板电脑来说,它失败了 Runtime.getRuntime().exec("/system/bin/which su "); 执行上述行后,返回true。 谢谢试试这个 公共类RootUtil{ private static final String TAG = "RootUtil"; public static boolean isDeviceRooted() {

我已经跟踪了链接 检查应用程序是否在根安卓设备上运行。对于某些设备和模拟器来说,它工作正常,但对于我的新三星平板电脑来说,它失败了

    Runtime.getRuntime().exec("/system/bin/which su ");
执行上述行后,返回
true

谢谢

试试这个

公共类RootUtil{

private static final String TAG = "RootUtil";

public static boolean isDeviceRooted() {
    return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
}

private static boolean checkRootMethod1() {
    String buildTags = android.os.Build.TAGS;
    return buildTags != null && buildTags.contains("test-keys");
}

private static boolean checkRootMethod2() {
    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;
}

private static boolean checkRootMethod3() {
    Process process = null;
    try {
        process = Runtime.getRuntime().exec(new String[]{"/system/xbin/which", "su"});
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        return in.readLine() != null;
    } catch (Throwable t) {
        return false;
    } finally {
        if (process != null) process.destroy();
    }
}

public static boolean isDeviceRootedV2() {
    try {
        Runtime.getRuntime().exec("su");
        return true;
    } catch (IOException e) {
        Log.e(TAG, "isDeviceRootedV2: " + e.getMessage());
        return false;
    }
}

}

调用isDeviceRootedV2()进行根目录检查如果您要查看我共享的链接,则此命令就在那里。