Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically lock into portrait mode for certain operations

Tags:

android

Is there a way to programmatically lock an app in portrait mode for certain operations, and then resume (and have the app rotate to landscape if the user is holding the device that way) after the operation is complete?

like image 596
synic Avatar asked Jul 11 '11 18:07

synic


People also ask

How do I force an app to stay in portrait mode?

Android Settings Start by going to Settings => Display and locate the “Device rotation” setting. On my personal cell phone, tapping this will reveal two options: “Rotate the contents of the screen,” and “Stay in portrait view.”

How do I lock orientation in Android programmatically?

setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE); Called on an activity, will lock it to landscape.


1 Answers

Try this:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //Do your operation setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); 
like image 102
OceanBlue Avatar answered Oct 07 '22 22:10

OceanBlue