Example usage for android.content Context getSharedPreferences

List of usage examples for android.content Context getSharedPreferences

Introduction

In this page you can find the example usage for android.content Context getSharedPreferences.

Prototype

public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);

Source Link

Document

Retrieve and hold the contents of the preferences file, returning a SharedPreferences through which you can retrieve and modify its values.

Usage

From source file:Main.java

public static String getUserToken(Context context) {
    SharedPreferences userPreferences = context.getSharedPreferences("umeng_general_config",
            Context.MODE_PRIVATE);
    String string = userPreferences.getString("jdycode", null);
    return string;
}

From source file:Main.java

public static boolean getNotifyPrayer(Context context) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
    return sharedPreferences.getBoolean(NOTIFY_PRAYER, true);
}

From source file:Main.java

public static void saveWIFIOnly(Context context, boolean isChecked) {
    SharedPreferences sp = context.getSharedPreferences("setting", Context.MODE_PRIVATE);
    sp.edit().putBoolean("isWIFIOnly", isChecked).commit();
}

From source file:Main.java

public static void remove(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.remove(key);/*  w  w w.ja  v a  2s.com*/
    editor.commit();
}

From source file:Main.java

public static String getChatBg(Context context, String key) {
    SharedPreferences spf = context.getSharedPreferences("chat", Context.MODE_PRIVATE);
    if (spf.contains(key)) {
        return spf.getString(key, "");
    }//from   w  ww .  j  av  a 2s  .  c  om
    return "";
}

From source file:Main.java

public static void setCameraActive(Context context, boolean fl) {
    SharedPreferences sd = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sd.edit();
    editor.putBoolean(CAMERA_ACTIVE, fl);
    editor.commit();/*from w w w.  j ava  2  s . c o m*/
}

From source file:Main.java

public static void setTimeActive(Context context, boolean fl) {
    SharedPreferences sd = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sd.edit();
    editor.putBoolean(TIME_ACTIVE, fl);
    editor.commit();/*  w w w.java 2 s . c  o m*/
}

From source file:Main.java

public static void setClearDefualtFlag(Context context, String flag) {
    SharedPreferences sp = context.getSharedPreferences("you_notification", Activity.MODE_PRIVATE);
    sp.edit().putString(CLEAR_AUTO_FLAG, flag).commit();
}

From source file:Main.java

public static String getMemberID(Context context) {
    SharedPreferences userPreferences = context.getSharedPreferences("umeng_general_config",
            Context.MODE_PRIVATE);
    String string = userPreferences.getString("ID", null);
    return string;
}

From source file:Main.java

public static void removeKey(String preName, Context context, String key) {
    SharedPreferences pre = context.getSharedPreferences(preName, Context.MODE_PRIVATE);
    Editor editor = pre.edit();//from w  ww .j  ava  2 s.  c  o  m
    editor.remove(key);
    editor.commit();
}