7

I'm using Cordova 3.3.0 with my Galaxy S3 (running latest Cyanogenmod) to test an app I'm working on; I need the app screen to remain in "portrait" mode and be locked even if the user rotates the device. No matter what I tried or tutorials I followed, the app is ignoring the preferences to lock the screen. What am I doing wrong?

Here's my config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.numediaweb.test" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Test</name>
    <description>
        Test.</description>
    <author href="http://test.com" email="abdel@test.com">
        me
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="orientation" value="portrait" />
    <preference name="fullscreen" value="true" />
    <preference name="SplashScreen" value="splash" />
    <preference name="SplashScreenDelay" value="3000" />
</widget>
Preston159
  • 300
  • 1
  • 3
  • 10
numediaweb
  • 16,362
  • 12
  • 74
  • 110

3 Answers3

14

Fixed in Cordova 3.4.1. Now preference orientation works!

<preference name="orientation" value="portrait" />
Juan R
  • 193
  • 2
  • 8
12

I just found an interesting answer after I posted the question (in the related widget right); It's a bug in Cordova and to fix it, you either edit the AndroidManifest.xml to something like;

<activity android:screenOrientation="portrait" android:configChanges=...

Or use a plugin.

FI prefer to edit the manifest as it is easy.

Community
  • 1
  • 1
numediaweb
  • 16,362
  • 12
  • 74
  • 110
  • 1
    The drawback is when you delete/rebuild your Android platform; you have to add the changes again :( Another thing with the plugin is that if you want to start your Cordova application pre-locked you have to edit the onCreate() activity.. – numediaweb Feb 13 '14 at 15:30
  • Provided plugin is deprecated, use this one: http://stackoverflow.com/a/32405384/1848600 – Gajotres Sep 04 '15 at 20:25
1

The solution is to edit the android manifest like this:

    <application
            android:icon="@drawable/icon"
            android:label="@string/app_name" >
            <activity
                android:name=".AppName"
                android:configChanges="orientation|keyboardHidden|screenSize"
                android:label="@string/app_name"
                android:launchMode="singleTask"
                android:screenOrientation="unspecified"
                android:theme="@android:style/Theme.Translucent.NoTitleBar" >

with unspecified android select the proper orientation for device. es. smartphone is portrait only, but tablet is portrait and landscape

Slumber86
  • 673
  • 6
  • 8