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

Enabling access to DefaultSharedPreferences #14

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
12 changes: 12 additions & 0 deletions src/android/Sharedpreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import android.content.Context;
import android.content.SharedPreferences;

import android.preference.PreferenceManager;

public class Sharedpreferences extends CordovaPlugin {
public static final String GET_DEFAULT_SHARED_PREFERENCES = "getDefaultSharedPreferences";
public static final String GET_SHARED_PREFERENCES = "getSharedPreferences";
public static final String PUT_STRING = "putString";
public static final String GET_STRING = "getString";
Expand Down Expand Up @@ -62,6 +65,15 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
}
//Put a Sting into the Shared Preferences File
//params key and value String type
}else if(GET_DEFAULT_SHARED_PREFERENCES.equals(action)){
try{
SharedPref = PreferenceManager.getDefaultSharedPreferences(cordova.getActivity().getBaseContext());
}catch(Exception e){
callbackContext.error("Error creating Default Shared Preferences" + e.getMessage());
return false;
}
callbackContext.success("Default Shared Preferences Created");
return true;
}else if(PUT_STRING.equals(action)){
editor = SharedPref.edit();
try{
Expand Down
3 changes: 3 additions & 0 deletions www/sharedpreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ var sharedpreferences = {
getSharedPreferences : function(file, mode, successCallback, errorCallback){
cordova.exec(successCallback, errorCallback, 'Sharedpreferences', 'getSharedPreferences', [file, mode])
},
getDefaultSharedPreferences: function( successCallback, errorCallback ) {
cordova.exec(successCallback, errorCallback, 'Sharedpreferences', 'getDefaultSharedPreferences', [])
},
putString: function(key, string, successCallback, errorCallback){
cordova.exec(successCallback, errorCallback, 'Sharedpreferences', 'putString', [key, string])
},
Expand Down