How do I detect landscape mode while maintaining my layouts in portrait mode?
I have an activity which maintains the portrait mode irrespective of actual mobile orientation. I can do this by adding android:screenOrientation="portrait"
to my activity configuration in manifest.
However, I want to detect screenOrientation while maintaining the activity in portrait.
I have tried with following code:
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
recordConfigChanges(newConfig); // Performs some variable changes or similar
}
// Maintain activity in portrait mode itself
Configuration customConfig = newConfig;
customConfig.orientation = Configuration.ORIENTATION_PORTRAIT;
super.onConfigurationChanged(customConfig);
}
The above code does not maintain portrait, it rotates the UI to landscape mode. Re-iterating the original question, how do I detect landscape mode while maintaining my layouts in portrait mode?