I wish to read these values from my Cordova/PhoneGap application's config.xml
at runtime:
- name
- copyright
- description
However, was surprised to see there is no 'Config
' feature in the API reference guide:
http://cordova.apache.org/docs/en/3.4.0/index.html
I've resorted to writing my own function that reads and parses this file manually, however I feel like there must be an (existing) better way.
Should developers be parsing config.xml manually to extract necessary info, or is there an existing plugin that can be used to do this?
For the ones who don't want to mess with the xhr queries, there are two plugins you can use:
1 plugin-buildinfo (just for Android and IOS but sooo great)
2 plugin-app-version (lighter but supports more platforms)
To start quickly with the second one, all you need to do is adding the plugin into your project:
and calling where you want as follows:
You could use following code on iOS, WP7, WP8, Windows8, and probably Ubuntu
for the Android you have to change path to file from
"../config.xml"
to"../../android_res/xml/config.xml"
Taken from Cordova mailing where discussed answer: https://www.mail-archive.com/dev@cordova.apache.org/msg14313.html
Also there not-official plugin for reading configuration: https://github.com/apache/cordova-labs/tree/cdvtest/cordova-plugin-appsettings
You could use following Cordova plugin:
Add your Custom Parameters in
Config.xml
as preference tags:Note: be sure the preference name should be a small letter (to work on IOS).
Then in your page Get a key's value from the
Config.xml
using the following script:For more detail see https://www.npmjs.com/package/cordova-plugin-customconfigparameters