Not really a question, but a note to other users.
I've seen some posts asking how to force an app into landscape only or portrait only, but the answers there weren't working for me. I finally got it working, so I thought I would post how I did it:
1)create a file in <app>/build/android called AndroidManifest.custom.xml
2)copy all content from AndroidManifest.xml into new custom file.
3)for every activity node, add the following line: android:screenOrientation="portrait" If you want landscape do that instead, if you want both you can do "portrait|landscape"
4)(the key that was tripping me up) again for each activity node, REMOVE "|orientation" from the android:configChanges section.
after rebuilding, you should have an app locked into the orientation of your choice
15 Answers
another way programmatically to force portrait to all views
if (Ti.Platform.osname == 'android'){ Ti.Gesture.addEventListener('orientationchange', function(e) { Ti.Android.currentActivity.setRequestedOrientation(Ti.Android.SCREEN_ORIENTATION_PORTRAIT); }); }
To force orientation to be 'portrait' only add following code in tiapp.xml
<android > <manifest> <application> <activity android:name="com.myActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation" > </activity> </application> </manifest> </android>
for some reason it looks like
var win = Ti.UI.createWindow({orientationModes:[Titanium.UI.PORTRAIT]});only works on iPhone, but for android you have to do
var win = Ti.UI.createWindow(); win.orientationModes=[Titanium.UI.PORTRAIT];this works perfectly now in 1.7.2
Ok, what I don't understand is that
Titanium.UI.orientation = Titanium.UI.LANDSCAPE_LEFT
seems to work in KitchenSink, although it results in landscape RIGHT for some reason...
Well, i'm running the same issue, but after a lot of testing this solution almost work fine, almost because in the landscape mode the app show the splash screen many times... This was testing over the emulator and over an android 2.1
1) Create a custom AndroidManifest.xml (copy this from original generated source "build/android/AndroidManifest.xml")
2) Copy this on the created folder "platform/android/AndroidManifest.xml" at the top level of your project.
3) Add this: android:screenOrientation="portrait" to all activities
4) remove this: "|orientation" from all activities.
Here is my AndroidManifest.xml.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.patagonialabs.mytest" android:versionCode="1" android:versionName="1"> <uses-sdk android:minSdkVersion="7" /> <!-- TI_MANIFEST --> <application android:icon="@drawable/appicon" android:label="Mytest" android:name="MytestApplication" android:debuggable="false"> <!-- TI_APPLICATION --> <activity android:name=".MytestActivity" android:label="Mytest" android:theme="@style/Theme.Titanium" android:configChanges="keyboardHidden" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="org.appcelerator.titanium.TiActivity" android:configChanges="keyboardHidden" android:screenOrientation="portrait"/> <activity android:name="org.appcelerator.titanium.TiTranslucentActivity" android:configChanges="keyboardHidden" android:theme="@android:style/Theme.Translucent" android:screenOrientation="portrait"/> <activity android:name="org.appcelerator.titanium.TiModalActivity" android:configChanges="keyboardHidden" android:theme="@android:style/Theme.Translucent" android:screenOrientation="portrait"/> <activity android:name="ti.modules.titanium.ui.TiTabActivity" android:configChanges="keyboardHidden" android:screenOrientation="portrait"/> <activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity" android:screenOrientation="portrait" /> <service android:name="org.appcelerator.titanium.analytics.TiAnalyticsService" android:exported="false" android:screenOrientation="portrait"/> </application> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.INTERNET"/> </manifest>
That tip made my day! (i'm working with 1.7.0 and still have the issue)
http://developer.appcelerator.com/question/103611/how-do-i-set-androidversioncode-and-androidversionname
Rather than doing the AndroidManifest.custom.xml (which will fail if you try to build with one), just take all of your <manifest> code and dump that into tiapp.xml. It works for me on 1.7.2!
Does forcing portrait in Android work yet? If so...does anyone have some code they can share with me.
thanks in advance!
in tiapp.xml
according to your starting view you should add the following to the equivalent activity tag
for example if you use TabGroup as a main view use the following
<android xmlns:android="http://schemas.android.com/apk/res/android"> <manifest> <application> <activity android:name="ti.modules.titanium.ui.TiTabActivity" android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait"/> </application> </manifest> </android>
so you should review frist the starting main view activity from AndroidManifest.xml under the build folder
and copy the activity tag as is then add the following attribute to it android:screenOrientation="portrait"
then add it as above to tiapp.xml
This problem seems to have reappeared with SDK 1.7.0
how about if you just want to force certain Android gui's to be in Portrait ONLY?
I'm looking at the manifest XML file, but what if i have certain screens that should be locked to portrait and others that should be locked to landscape? can i add a new activity for those windows? how do i make sure those windows are connecting to that information?
try this in yourFile.js
win.orientationModes = [Ti.UI.PORTRAIT];
Hey guys. This should be simple, but I really can't get my Android app to be forced in portrait mode. I've tried every trick I've found on the forums. Please help!
FYI - The orientation issue on Android has been fixed and should be in the next release of Titanium :)
Your Answer
Think you can help? Login to answer this question!