Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try the following to disable and enable orientation via code (this will work in API level 7 and up) :</p> <pre><code>public static void disableRotation(Activity activity) { final int orientation = activity.getResources().getConfiguration().orientation; final int rotation = activity.getWindowManager().getDefaultDisplay() .getOrientation(); // Copied from Android docs, since we don't have these values in Froyo // 2.2 int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8; int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9; if (Build.VERSION.SDK_INT &lt;= Build.VERSION_CODES.FROYO) { SCREEN_ORIENTATION_REVERSE_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; SCREEN_ORIENTATION_REVERSE_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } } public static void enableRotation(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload