Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you force a landscape orientation for mobile apps built with cordova-cli?

I'm using cordova cli to build my app. I want to target both android and ios (maybe more).

As I want this to be true for all platforms, I was hoping I could simply define this as a preference in the config.xml like this:

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

because this is apparently how it works in the phonegap build https://build.phonegap.com/docs/config-xml

I assume the features supported in config.xml by phonegap build are different to those by cordova-cli?

I know I can force it in the android app by inserting android:screenOrientation="landscape" into my AndroidManifest.xml, but that's no good because it will be over-written the next time I perform a cordova build.

Any suggestions?

like image 226
matt burns Avatar asked Mar 08 '13 11:03

matt burns


2 Answers

This is no longer the case. The "orientation" preference in the config.xml is now honored by the cordova cli starting from version 3.4

This is the corresponding issue : https://issues.apache.org/jira/browse/CB-5634

like image 84
brahmana Avatar answered Oct 26 '22 18:10

brahmana


Simply put, it's not possible to set the orientation using a preference element in the www/config.xml. After inspecting the cordova-cli code it appears that only the version and entry class package are updated in the AndroidManifest.xml.

For a list of supported preferences see the Cordova Docs.

Added configurations to the AndroidManifest.xml file should not be lost on cordova build, unless the config option is pulled from somewhere else (i.e. version).

like image 41
Jonathan Dixon Avatar answered Oct 26 '22 18:10

Jonathan Dixon