Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lock/unlock orientation

To lock my orientation to portrait, I use:

activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

I'm unsure what flag tells the activity to go back to relying on the device orientation. I imagine it is one of these:

SCREEN_ORIENTATION_FULL_SENSOR
SCREEN_ORIENTATION_SENSOR
SCREEN_ORIENTATION_UNSPECIFIED
SCREEN_ORIENTATION_USER


On another note, why isn't the android documentation open source? The documentation is completely lacking. Very few of the functions and flags have useful descriptions.

like image 369
Matt Avatar asked Jun 15 '11 16:06

Matt


People also ask

How do I unlock my orientation lock?

Swipe up from the bottom edge of your screen to open Contol Center. Tap the Portrait Orientation Lock button to make sure that it's off. Turn your iPhone or iPod touch sideways.

How do I get my iPhone to rotate?

To disable Screen Rotation Lock, unlock your iPhone so that you're on the home screen and swipe down from the top right of your screen to reveal the Control Center. 2. Locate the icon featuring a small lock with an arrow curving around it. If Screen Rotation Lock is active, this will appear highlighted.

How do I stop my lock screen from rotating?

Short guide: Tap the Settings icon to open the Settings app. Scroll down and tap Accessibility. Scroll down to Interaction controls and tap Auto-rotate screen to turn it off.

Why is the iPhone screen not rotating?

Turn off iPhone Screen Rotation Lock If your screen won't rotate, it could be because you've got Rotation Lock turned on. To check whether the screen rotation lock is turned on, look in the top right corner of the screen next to the battery indicator for an icon that looks like an arrow curving around a lock.


2 Answers

Per http://developer.android.com/reference/android/R.attr.html#screenOrientation (screenOrientation being what those values are linked to if you dig through the documentation), SCREEN_ORIENTATION_SENSOR or SCREEN_ORIENTATION_FULL_SENSOR will do it, depending on how much flexibility you want -- however, I suspect what you really want is to go back to the default setting, which is SCREEN_ORIENTATION_UNSPECIFIED so that it goes back to the system defaults, including any the user set.

like image 171
Arthur Shipkowski Avatar answered Oct 21 '22 06:10

Arthur Shipkowski


An easy fix for this that worked for me is to add a line to AndroidManifest.xml like so:

Add android:screenOrientation="portrait"> in the application section.

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".App"
              android:label="@string/app_name"
              android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>
like image 31
TyrusC Avatar answered Oct 21 '22 04:10

TyrusC