lock/unlock orientation
Asked Answered
E

3

14

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.

Embry answered 15/6, 2011 at 16:43 Comment(2)
Regarding your additional note: I found this by clicking through, from developer.android.com/reference/android/app/… to the 'orientation constant as used in' to the meanings of the constants.Explosion
Yeah, and I was on that page and clicked the ActivityInfo.screenOrientation link before making this post. The next page is completely useless unless you again click "screenOrientation", which gives the actual description of the flags. I don't understand why clicking one of the flags on the "ActivityInfo.screenOrientation" page doesn't provide an explanation of it.Embry
E
20

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.

Explosion answered 15/6, 2011 at 16:50 Comment(2)
Thanks. I guess I failed to click the "screenOrientation" link a second time to take me to the actual attribute page.Embry
I think it actually took me three or four clicks to get there, so I understand your annoyance.Explosion
L
1

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>
Lookout answered 22/7, 2011 at 20:29 Comment(1)
in the ACTIVITY section, not the Application section.Melancholic
N
0

If the "android:immersive"attribute is set to"true " in the app's manifest entryfor this activity, the ActivityInfo.flagsmember always has its FLAG_IMMERSIVE bit set, even if the immersive mode is changed at runtime using the "setImmersive()" method.

Notch answered 27/7, 2019 at 4:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.