Android: screenOrientation = "portrait" is ignored in Jellybean

android: screenOrientation = "portrait" is ignored in Jellybean. If I turn the phone into a landscape, it will change orientation independently. I tried several phones. Is there any new flag I should use?

+4
source share
1 answer

You can try to do this programmatically,

@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); switch (newConfig.orientation) { case Configuration.ORIENTATION_PORTRAIT: // taking action on event lockScreenRotation(Configuration.ORIENTATION_PORTRAIT); break; case Configuration.ORIENTATION_LANDSCAPE: // taking action on event lockScreenRotation(Configuration.ORIENTATION_LANDSCAPE); break; case Configuration.ORIENTATION_SQUARE: // taking action on event lockScreenRotation(Configuration.ORIENTATION_SQUARE); break; default: throw new Exception("Unexpected orientation!!!"); break; } private void lockScreenRotation(int orientation) { // Stop the screen orientation changing during an event switch (orientation) { ... case Configuration.ORIENTATION_PORTRAIT: this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; case Configuration.ORIENTATION_LANDSCAPE: this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; ... case default: this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); break; } } 
+2
source

All Articles