3

I develop a mobile application using phonegap.

The main Issue I'm facing is to store an application setting (Display language, Notification Allow , ...) in way that allow me to access them from java code and from the javascript code

I found that I have two ways to store those settings:

  1. Using database.
  2. Using SharedPreferences.
  3. ???

I did not find a suitable cordova plugin that allow me to store and load from sharedPreferences and hopeful if there is a ready plugin to act with it,

and wonder which way is better in performance and more common in general.

Hanihh
  • 305
  • 1
  • 4
  • 13

1 Answers1

1

You can use the regular options menu and PreferenceActivity when using PhoneGap that will let your app to easily store Settings in the SharedPreferences.

If you need to read settings from your web page just use the JavaScriptInterface to communicate between the page and native.

Activity onCreate:

bridge = new PGBridge(this);
appView.addJavascriptInterface(bridge, "bridge");

public static class PGBridge{
private DroidGap droidGap;
    public PGBridge(DroidGap droidGap){
        this.droidGap = droidGap;
    }
    public String getPreference(String preference){
        return PreferenceManager.getDefaultSharedPreferences(droidGap).getString(preference, "");
    }

In JS:

var preference = window.bridge.getPreference("something");
Nicklas Gnejs Eriksson
  • 3,395
  • 2
  • 21
  • 19