enable Activity Orientation - Android Activity

Android examples for Activity:Activity Orientation

Description

enable Activity Orientation

Demo Code


//package com.java2s;

import android.app.Activity;

import android.content.pm.ActivityInfo;

import android.provider.Settings;

public class Main {
    public static void enableOrientation(Activity activity, boolean enable) {
        if (enable) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
            Settings.System.putInt(activity.getContentResolver(),
                    Settings.System.ACCELEROMETER_ROTATION, 1);
        } else {//ww w.  ja  v  a  2s  . c  o m
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            Settings.System.putInt(activity.getContentResolver(),
                    Settings.System.ACCELEROMETER_ROTATION, 0);

        }
    }
}

Related Tutorials