Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top