Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a cordova plugin to read values from config.xml?

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?

like image 465
thinkbigthinksmall Avatar asked Mar 30 '14 12:03

thinkbigthinksmall


People also ask

How do I add a plugin to config xml Cordova?

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.

Is Cordova discontinued?

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.

What is config xml in Cordova?

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.


2 Answers

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);
});
like image 106
Asqan Avatar answered Sep 24 '22 08:09

Asqan


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

like image 40
Ibrahim Wahdan - Abu Yazan Avatar answered Sep 22 '22 08:09

Ibrahim Wahdan - Abu Yazan