If possible, do not use SCREEN_ORIENTATION_LANDSCAPE or SCREEN_ORIENTATION_PORTRAIT. Use instead:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
This allows the user to orient the device both in landscape orientation and portrait orientation. If you've ever had to play a game with a charging cable in your stomach, then you know exactly why the presence of both orientations is important for the user.
Note. For at least a few phones that I checked, it only allows portrait mode "right side", however, SENSOR_PORTRAIT works correctly on tablets.
Note. This feature was introduced at API level 9, so if you must support 8 or lower (unlikely at the moment), use:
setRequestedOrientation(Build.VERSION.SDK_INT < 9 ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); setRequestedOrientation(Build.VERSION.SDK_INT < 9 ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
Paul Aug 10 '15 at 17:58 2015-08-10 17:58
source share