About the author
Make a call to setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); to get the app displayed in landscape mode, and setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); to switch to portrait mode.
To detect the current screen orientation that has been set by the application, here's how you do it:
int LOrientation = getRequestedOrientation();if (LOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {} ...
if (LOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { } ...
To detect the current screen orientation without having called getRequestedOrientation before, call getResources().getConfiguration().orientation. The value of orientation will be one of the ActivityInfo.SCREEN_ORIENTATION_xxx values (SCREEN_ORIENTATION_LANDSCAPE, SCREEN_ORIENTATION_PORTRAIT, SCREEN_ORIENTATION_SQUARE).
To get the requested screen orientation, call getRequestedOrientation.If the application did not request a screen orientation before, it returns -1.