简体   繁体   中英

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?

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

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 (ie version).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM