I wish to read these values from my Cordova/PhoneGap application's config.xml
at runtime:
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?
When adding plugins or platforms, use the --save flag to add them to config. xml. Ex: cordova platform add android --save. Existing projects can use cordova plugin save and cordova platform save commands to save all previously installed plugins and platforms into your project's config.
Apache Cordova Is Retired: Alternatives for Cross Platform Mobile Development in 2022. Future trends of cross-platform mobile development are already starting to emerge, and it appears that Apache Cordova won't be included in the list of frameworks that power hybrid web apps for mobile devices.
config. xml is a global configuration file that controls many aspects of a cordova application's behavior. This platform-agnostic XML file is arranged based on the W3C's Packaged Web Apps (Widgets) specification, and extended to specify core Cordova API features, plugins, and platform-specific settings.
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:
cordova plugin add https://github.com/whiteoctober/cordova-plugin-app-version.git
and calling where you want as follows:
cordova.getAppVersion(function (version) {
alert(version);
});
You could use following Cordova plugin:
cordova plugin add cordova-plugin-customconfigparameters
Add your Custom Parameters in Config.xml
as preference tags:
<preference name="name" value="Ibrahim"/>
<preference name="copyright" value="Direct Direction 2017"/>
<preference name="description" value="Information Technology"/>
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:
var paramkeyArray=["name","copyright","description"];
CustomConfigParameters.get(function(configData){
console.log(configData.name);
console.log(configData.copyright);
console.log(configData.description);
},function(err){
console.log(err);
},paramkeyArray);
For more detail see https://www.npmjs.com/package/cordova-plugin-customconfigparameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With