3

How do I lock the orientation of my phonegap application to portrait?

My current config.xml is using this preference:

<preference name="orientation" value="portrait"/>

However it makes no difference and I can still orientate my application in both orientations by rotating my mobile test device.

Also if you know of a an active phonegap/cordova community could you please post a link?

jshbrntt
  • 5,134
  • 6
  • 31
  • 60
  • What type of os you're testing on? Maybe this helps? http://stackoverflow.com/questions/18477050/phonegap-3-0-0-locking-orientation – Eric Geurts Jan 02 '14 at 14:10

1 Answers1

9

If you are working with Android you can add

android:screenOrientation="portrait"

to the main activity tag in the platforms/android/AndroidManifest.xml file.

So

<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="inappbrowser" android:theme="@android:style/Theme.Black.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

becomes

<activity android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="inappbrowser" android:theme="@android:style/Theme.Black.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Just another note in case you want other portrait variations. From: http://developer.android.com/guide/topics/manifest/activity-element.html

You could use reversePortrait or sensorPortrait

Dustin Simpson
  • 749
  • 4
  • 10
  • Why should it have to be added here? Shouldn't it look at the config.xml in the 'www' folder and generate this from the when it builds for that platform? – jshbrntt Jan 02 '14 at 17:37
  • One would think, and I could be wrong about the best way to do it. It has just been my experience. The same is true for iOS in xcode like the answer that Eric Geurts linked above. – Dustin Simpson Jan 02 '14 at 17:39
  • I know exactly how you feel! – Dustin Simpson Jan 02 '14 at 18:25