Android Screen Orientation Set setOrientation(Activity activity, String orientation)

Here you can find the source of setOrientation(Activity activity, String orientation)

Description

set Orientation

License

Open Source License

Declaration

static public void setOrientation(Activity activity, String orientation) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.app.Activity;

import android.content.pm.ActivityInfo;

import android.util.Log;

public class Main {
    private static final String TAG = "Helper";

    static public void setOrientation(Activity activity, String orientation) {
        if (orientation.equals("LANDSCAPE")) {
            Log.i(TAG, "Forcing orientation to landscape");
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else if (orientation.equals("PORTRAIT")) {
            Log.i(TAG, "Forcing orientation to portrait");
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else if (orientation.equals("AUTOMATIC")) {
            Log.i(TAG, "Automatic orientation");
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        } else {/*from  w  w  w . j  a  va2  s .  co  m*/
            Log.i(TAG, "No orientation change");
        }
    }
}

Related

  1. getDisplayRotation(Activity activity)
  2. setScreenHorizontal(Activity activity)
  3. setScreenVertical(Activity activity)