I'm new to android my question is, Is it possible to change orientation programmatically? If yes, how can we do that?
The display orientation of the application may be locked. In the game, tap the “Settings” button in the toolbar. In the “Settings” display, scroll down to the “Lock Orientation” option. Review the current setting to ensure it is either set to “auto” or your preferred fixed orientation.
You can define your app orientation within Unity under Player Settings -> Resolution and Presentation -> Orientation. Our Core Samples use this to lock to portrait mode.
You can change the screen orientation by clicking either of the "rotate" buttons in that side panel. Just click on Rotate button to change the landscape to portrait and vice versa. Unfortunately, although this rotates the emulator depiction, it doesn't signal the applications to rotate.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Also add this in your manifest file (under activity):
android:configChanges = "orientation"
Yes, use setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); to force orientation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With