How to set app to be portrait only?

Synnipoe picture Synnipoe · Oct 30, 2016 · Viewed 24.8k times · Source

The only thing I can find is to use this:

android:configChanges="orientation"
    android:screenOrientation="portrait"

but it stays as normal. My manifest:

?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:configChanges="orientation"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Answer

Mor Paz picture Mor Paz · Oct 30, 2016

As seen in the question: I want my android application to be only run in portrait mode?

You should set the configChanges and screenOrientation flags for every activity, and not at the root of your manifest.

So it should look like this:

<activity android:name=".MainActivity"
  android:configChanges="orientation"
  android:screenOrientation="portrait">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>