Back to project page socialcde4android.
The source code is released under:
MIT License
If you think the Android project socialcde4android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package it.uniba.socialcde4android.utility; //from w w w . j av a 2 s . c o m import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.view.Surface; import android.view.WindowManager; public class ScreenUtility { public static void lockScreenOrientation(Activity activity){ int orientation = activity.getRequestedOrientation(); int rotation = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); switch (rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; default: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; } activity.setRequestedOrientation(orientation); } }