4
votes

The app i am developing should be displayed only in landscape mode.

In my app descriptor i have

    <aspectRatio>landscape</aspectRatio>
    <autoOrients>false</autoOrients> 

On iOS devices app is launched in landscape mode and everything works as expected.

But when i tried to deploy on my android device ( Samsung galaxy S3 ), the app is launched in portrait mode.

When I modify the descriptor file to read :

    <aspectRatio>landscape</aspectRatio>
    <autoOrients>true</autoOrients> 

then the app will be changing orientation.

While debugging i found out that the apps orientation when starting is stage.orientation == "default"

Also i have added android:screenOrientation="landscape" to android specific configurations in my app.xml (the app descriptor file):

<android>
    <manifestAdditions>
        <![CDATA[
        <manifest android:installLocation="auto">
            <uses-permission android:name="android.permission.INTERNET"/>
            <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
            <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
            <uses-permission android:name="android.permission.VIBRATE"/>
            <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
            <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
            <uses-permission android:name="android.permission.WAKE_LOCK"/>
            <uses-permission android:name="android.permission.CAMERA"/>
            <uses-permission android:name="android.permission.RECORD_AUDIO"/>
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
            <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

            <uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch"/>
            <application android:enabled="true">
                <activity android:excludeFromRecents="false" android:screenOrientation="landscape">
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN"/>
                        <category android:name="android.intent.category.LAUNCHER"/>
                    </intent-filter>
                </activity>
            </application>
        </manifest>
        ]]>
        </manifestAdditions>

     <!--Color depth for the app (either "32bit" or "16bit"). Optional. Default 16bit before namespace 3.0, 32bit after -->
    <!--<colorDepth></colorDepth>-->
</android>

Is this a known issue? What could be the cause of this?

EDIT:

I ended up using stage.setAspectRatio( StageAspectRatio.LANDSCAPE ); in my main class. It will work even with devices that have default orientation other than PORTRAIT

1

1 Answers

2
votes

I had similar problems with orientation. As i needed to restrict orientation change only for certain devices i solved it by setting values at runtime (before app has fully initialised).

In main application tag, listen for preinitialize event:

<s:Application ...
    preinitialize="preinit()">

And set orientation values in listener:

private function preinit():void
{
    systemManager.stage.setOrientation(StageOrientation.ROTATED_LEFT);
    systemManager.stage.autoOrients = false;
}

Or try StageOrientation.ROTATED_RIGHT instead.

Edit: As Josh commented, this will only work for devices with portrait as the default (ie: your Samsung S3).