Reputation: 15
I want my application to be able to get the current screen orientation and change it to landscape/portrait. Which things do I need to declare in the manifest file to deal with screen orientation ?
Upvotes: 1
Views: 1894
Reputation: 5167
If you want to set the orientation to Landscape:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
If you want to set the orientation to Portrait:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Also add android:configChanges="orientation|screenSize"
in your manifest to avoid reloading the activity on orientation change.
Upvotes: 1
Reputation: 183
For getting the orientation u can use:
getResources().getConfiguration().orientation
And for setting the orientation:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
Upvotes: 0