lock Activity Orientation - Android Activity

Android examples for Activity:Activity Orientation

Description

lock Activity Orientation

Demo Code


//package com.java2s;
import android.app.Activity;

import android.content.pm.ActivityInfo;
import android.content.res.Configuration;

public class Main {
    public static int lockActivityOrientation(Activity activity) {
        int oldOrientation = activity.getRequestedOrientation();

        int currentOrientation = activity.getResources().getConfiguration().orientation;
        if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
        } else {/*from  w w  w .  jav  a  2  s  .com*/
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
        }

        return oldOrientation;
    }
}

Related Tutorials