Cordova Plugin for Android SharedPreferences
###in.edelworks.sharedpreferences
#####Author: R. Pramod Nair #####Organization: EdelWorks edelworks.in
###Platform Support Android
###Installation #####$> cd project-path #####$> cordova plugin add https://github.com/edelworksgithub/SharedPreferences.git
###Uninstallation #####$> cd project-path #####$> cordova plugin remove in.edelworks.sharedpreferences
###Reference for Shared Preferences in Android Android Developer - Saving Key-Value Sets
###How to #####Initialize shared Preference file
filename - SharedPrefernces File Name
mode - mode of Preference file. two accepted (MODE_APPEND, MODE_PRIVATE)
#####Save String value into Preference file
#####Save Integer value into Preference file
#####Save Long value into Preference file
#####Save Boolean value into Preference file
#####Get String value from Preference file
#####Get Integer value from Preference file
#####Get Long value from Preference file
######NOTE: returned value will be in String type. Please use eval() or parseInt() for calculation use
#####Get Boolean value from Preference file
######NOTE: returned value will be 0 - for false and 1 - true
###Newly Added (Thanks to @octera)
#####Save Float value into Preference file
#####Get Float value from Preference file
###Examples #####Initialize shared Preference file
function createPref(filename, mode){
sharedpreferences.getSharedPreferences(filename, mode, successHandler, errorHandler);
}
function successHandler(result){
alert("SUCCESS: \r\n"+result );
}
function errorHandler(result){
alert("ERORR: \r\n"+result );
}
#####Put Values
function putValue(key, value, type){
switch(type){
case "string":
sharedpreferences.putString(key, value, successHandler, errorHandler);
break;
case "int":
sharedpreferences.putInt(key, value, successHandler, errorHandler);
break;
case "long":
sharedpreferences.putLong(key, value, successHandler, errorHandler);
break;
case "boolean":
sharedpreferences.putBoolean(key, value, successHandler, errorHandler);
break;
}
}
#####Get Values
function getValue(key, type){
switch(type){
case "string":
sharedpreferences.getString(key, successHandler, errorHandler);
break;
case "int":
sharedpreferences.getInt(key, successHandler, errorHandler);
break;
case "long":
sharedpreferences.getLong(key, successHandler, errorHandler);
break;
case "boolean":
sharedpreferences.getBoolean(key, successHandler, errorHandler);
break;
}
}
#####Remove a Key from Preference file
function remove(key){
sharedpreferences.remove(key, successHandler, errorHandler);
}
#####Clear a preference file
function clearAll(){
sharedpreferences.clear(successHandler, errorHandler);
}