Example usage for android.preference PreferenceManager getDefaultSharedPreferences

List of usage examples for android.preference PreferenceManager getDefaultSharedPreferences

Introduction

In this page you can find the example usage for android.preference PreferenceManager getDefaultSharedPreferences.

Prototype

public static SharedPreferences getDefaultSharedPreferences(Context context) 

Source Link

Document

Gets a SharedPreferences instance that points to the default file that is used by the preference framework in the given context.

Usage

From source file:Main.java

public static boolean getDownloadOFFSwitch(Context context, String modeName) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean ret = settings.getBoolean(modeName, true);
    return ret;/* ww  w.j  av  a2 s. c  o  m*/
}

From source file:Main.java

public static void saveKeyValueData(String key, String value, Activity ctx) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(ctx);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putString(key, value);//from  w ww  .  j a  v a  2  s  .  c  o m
    editor.commit();
}

From source file:Main.java

public static boolean getBooleanFromDefault(Context context, String key, boolean defValue) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    return sp.getBoolean(key, defValue);
}

From source file:Main.java

public static void setSharedBooleanPref(Context context, String key, boolean value) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean(key, value);//from w  w  w  .  j a  v  a 2 s .co  m
    editor.apply();
}

From source file:Main.java

public static void setInt(Context context, final String key, final int value) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    settings.edit().putInt(key, value).commit();
}

From source file:Main.java

public static boolean getNotificationSwitch(Context context, String modeName) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean ret = settings.getBoolean(modeName, true);
    return ret;/*from w w w  .j a  va2  s.  c  o m*/
}

From source file:Main.java

public static boolean getBoolean(Context context, String key, final boolean defaultValue) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs.getBoolean(key, defaultValue);
}

From source file:Main.java

public static final boolean hasAdvertisingID(Context c) {
    try {//from  w  ww. j a  v  a  2  s .co m
        if (PreferenceManager.getDefaultSharedPreferences(c).contains(PREF_ADV)) {
            return true;
        }
    } catch (Exception e) {
    }
    return false;
}

From source file:Main.java

public static void reset(final Context ctx) {

    Editor edit = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
    edit.clear();/*from   ww w  .  jav  a2  s .c o  m*/
    edit.commit();
}

From source file:Main.java

public static void saveData(Context context, String key, String value) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(key, value);/*from  ww  w. java 2  s .co  m*/
    editor.apply();
}