Skip to content Skip to sidebar Skip to footer

Orientation Lock

How can I prevent my app form rotating. I want it so if the user is in portrait mode, the app will always be in portrait mode, and if they start the app in landscape the app will a

Solution 1:

public static void lockOrientation(Activity a) {
    if (a.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {
        a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}

public static void unlockOrientation(Activity a) {
    a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}

Post a Comment for "Orientation Lock"