Restrict application to be open in rooted phone android.

public Boolean isDeviceRooted(Context context){
    boolean isRooted = isrooted1() || isrooted2();
    return isRooted;
}

private boolean isrooted1() {

    File file = new File("/system/app/Superuser.apk");
    if (file.exists()) {
        return true;
    }
    return false;
}

// try executing commandsprivate boolean isrooted2() {
    return canExecuteCommand("/system/xbin/which su")
            || canExecuteCommand("/system/bin/which su")
            || canExecuteCommand("which su");
}

private static boolean canExecuteCommand(String command) {
    boolean executedSuccesfully;
    try {
        Runtime.getRuntime().exec(command);
        executedSuccesfully = true;
    } catch (Exception e) {
        executedSuccesfully = false;
    }

    return executedSuccesfully;
}

Comments

Popular Post

Implement search functionality with help of edittext, rxjava and retrofit 2 in android.

QR code scanner using Zxing library. Scanner for android

Store GPS Location in image background android.

Storing captured image or an image picked from a gallery in internal storage using file provider android.

Shortcut for android for every version, android shortcut for oreo, android shortcut for nougat.