In my project's config.xml
I added a custom preference:
<preference name="FooBar" value="Baz" />
Then, in my custom plugin's JavaScript inside <plugin>/www/plugin.js
I want to access the value of such feature.
Does Cordova exposes those values to the JavaScript side? I couldn't find any information in the documentation about it.
Tried:
var argscheck = require('cordova/argscheck');
argscheck.getValue('FooBar'); // Returns just FooBar
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.
The config. xml file is the place where we can change the configuration of the app. When we created our app in the last tutorial, we set reverse domain and name. The values can be changed in the config.
The plugin. xml file is an XML document in the plugins namespace: http://apache.org/cordova/ns/plugins/1.0 .
You could use following code on iOS, WP7, WP8, Windows8, and probably Ubuntu
function readConfig() {
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function () {
var parser = new DOMParser();
var doc = parser.parseFromString(xhr.responseText, "application/xml");
alert("Description : " +
doc.getElementsByTagName("description").item(0).textContent);
});
xhr.open("get", "../config.xml", true);
xhr.send();
}
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/[email protected]/msg14313.html
Also there not-official plugin for reading configuration: https://github.com/apache/cordova-labs/tree/cdvtest/cordova-plugin-appsettings
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