enable Orientation change - Android android.app

Android examples for android.app:Activity

Description

enable Orientation change

Demo Code

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 {//from   w  w  w.  j  a va  2 s . c o m
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            Settings.System.putInt(activity.getContentResolver(),
                    Settings.System.ACCELEROMETER_ROTATION, 0);

        }
    }

}

Related Tutorials