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 void putString(Context context, String key, String value) {
    try {/*from   www  .j  a v  a  2s.c  om*/
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        sp.edit().putString(key, value).apply();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

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

From source file:Main.java

public static int getInt(Context context, final String key, final int defaultValue) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    return settings.getInt(key, defaultValue);
}

From source file:Main.java

public static void putSharedPreferencesFloat(Context context, String key, float val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putFloat(key, val);
    edit.apply();/*from w w  w  . j a va  2  s  . co m*/
}

From source file:Main.java

public static void setSettingLong(Context context, final String key, final long value) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    settings.edit().putLong(key, value).apply();
}

From source file:Main.java

public static void putSharedPreferencesString(Context context, String key, String val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putString(key, val);
    edit.commit();/* www .ja v a2  s  .co  m*/
}

From source file:Main.java

public static float getSharedPreferencesFloat(Context context, String key, float _default) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    return preferences.getFloat(key, _default);
}

From source file:Main.java

public static boolean isSyncConfigured(Context context) {
    String syncSource = PreferenceManager.getDefaultSharedPreferences(context).getString("syncSource", "");

    if (TextUtils.isEmpty(syncSource))
        return false;
    else/* ww  w  .j  av a2s. c o  m*/
        return true;
}

From source file:Main.java

public static void putBoolean(Context context, String key, boolean value) {
    try {//from  w w  w.jav a  2 s.c  om
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        sp.edit().putBoolean(key, value).apply();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static long getLong(Context context, final String key, final long defaultValue) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    return settings.getLong(key, defaultValue);
}