TheCocoaProject/cordova-plugin-nativestorage

Access stored values in Android

GillesC opened this issue · 1 comments

Variables can be accessed in Android by using the getString method provided by SharedPreferences. If NativeStorage API is used prior to v2.0 you need to use getBoolean, getString, getDouble,... corresponding to the variable type you have stored in JavaScript.

An Android snippet can be found here:

private static final String PREFS_NAME = "NativeStorage";
private static final String KEY= "reference_to_var";
String value = getValue(Activity.this, KEY , null);
      

String getValue(Context context, String key, String defaultValue) {
   SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE);
   return settings.getString(key, defaultValue);
}

It is important that you use "NativeStorage" as the name of the preferences.

Question on StackOverflow.
Question on Github

Hi @GillesC !

Could you please see my problem here ?
https://stackoverflow.com/questions/47073611/cordova-nativestorage-and-android

Your suggestion just don't work for me.