mohamnag
mohamnag

Reputation: 2883

Plugin preferences in config.xml

I'm developing a plugin for cordova and I need to let user store some settings somewhere after installing the plugin. So I thought that the best place would be the config.xml file. As there are also some core plugins that does this (like StatusBar). This is ok on iOS but I could not find a way to access the values of config.xml file from android native code.

all I have in an andorid native code is access to the static Config instance but it does really return nothing about config values.

On iOS this is however possible to access any value of any key inside config file like what is done here: https://github.com/apache/cordova-plugin-statusbar/blob/master/src/ios/CDVStatusBar.m#L77

which actually accesses this dictionary populated with the values of config file here: https://github.com/apache/cordova-ios/blob/master/CordovaLib/Classes/CDVViewController.m#L36

is there another way to access same data on android too?

Upvotes: 2

Views: 2334

Answers (2)

blakgeek
blakgeek

Reputation: 419

A simpler alternative is to use the preferences property of CordovaPlugin.

preferences.getString("SomePreference", "DefaultValue");

It also supports getting Integers, Doubles and Booleans. I can't find any documentation but you can view the source here source

Upvotes: 3

mohamnag
mohamnag

Reputation: 2883

so I found the solution. on android all of the preferences tags are added as extras to the intent, so you can basically back data from your intent like this:

cordova.getActivity().getIntent().getStringExtra("name-of-preference-tag");

Upvotes: 1

Related Questions