Remove orientation restricitons programmatically
android, android-layout
Solution
Whether or not you've set `android:screenOrientation` in your Manifest, you can programmatically set the orientation with Activity.setRequestedOrientation().
In essence, "removing the restriction" is accomplished by
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
after which the Activity will exhibit the default behavior of changing screen orientation when the physical device orientation changes.
It's likely, however, that you want to actually match the current physical device orientation at the same time. I haven't tried it, but I'm pretty sure that if all you did was the above, if the device was physically in a landscape orientation when you did it, then you'd stay in portrait mode until you physically moved the device to portrait and back to landscape.
What I would do is be sure to set `android:configChanges="orientation"` in your Manifest and override Activity.onConfigurationChanged(), in which you can, according to your condition, either perform the orientation change or cache the orientation. Then whenever your condition changes, you'll have the current physical orientation handy so you can change it at that point if necessary.
Problem
In my manifest I've setup an activity restricted to portrait orientation. But I need to remove this restriction on condition. So, how do I achieve removing orientation restrictions programmatically ? upd: my present settings are: ``` <activity android:name=".activity.MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait" android:configChanges="orientation"> /** * Defines whether the device being used is a tablet and if so adds horizontal orientation option. */ protected void _updateScreenOrientationModes(){ if(((MyApplication) getApplication())._isTablet == true) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } ```