Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access stored values in Android #53

Closed
GillesC opened this issue Nov 28, 2016 · 1 comment
Closed

Access stored values in Android #53

GillesC opened this issue Nov 28, 2016 · 1 comment

Comments

@GillesC
Copy link
Collaborator

GillesC commented Nov 28, 2016

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

@GillesC GillesC changed the title onStackOverflow Access stored values in Android Nov 28, 2016
@GillesC GillesC closed this as completed Nov 28, 2016
@Charles808
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants