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

private static SharedPreferences getPrefences(Context context) {
    if (mSp == null) {
        mSp = context.getSharedPreferences(CONFIG_SP, Context.MODE_PRIVATE);
    }//from w ww .  ja  va2  s  . co m
    return mSp;
}

From source file:Main.java

public static String getStringProperty(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(DEFAULT_FILE_NAME, Context.MODE_PRIVATE);
    return sp.getString(key, null);
}

From source file:Main.java

public static boolean getIsOpen(final Context mContext) {
    SharedPreferences preferences = mContext.getSharedPreferences("com.livechat.chat_open",
            Context.MODE_PRIVATE);
    return preferences.getBoolean("isOpen", false);
}

From source file:Main.java

public static Map<String, ?> getAll(Context context, String file_name) {
    SharedPreferences sp = context.getSharedPreferences(file_name, Context.MODE_PRIVATE);
    return sp.getAll();
}

From source file:Main.java

/**
 *
 * @param ctx//  w  w  w. ja  va  2  s . c o  m
 * @param key
 * @return
 */
public static boolean removeGlobalSetting(Context ctx, String key) {
    SharedPreferences setting = ctx.getSharedPreferences(ctx.getPackageName(), 0);
    return setting.edit().remove(key).commit();
}

From source file:Main.java

public static void SpIntertInt(Context c, String key, int value) {
    SharedPreferences sp = c.getSharedPreferences("XGram", Context.MODE_WORLD_READABLE);
    SharedPreferences.Editor editor = sp.edit();
    editor.putInt(key, value);/*www.  j a v  a2 s.c  om*/
    editor.apply();
}

From source file:Main.java

public static void saveLong(Context context, String key, long value) {
    Editor editor = context.getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE).edit();
    editor.putLong(key, value);/*from w ww .jav  a 2 s. co m*/
    editor.commit();
}

From source file:Main.java

public static int getDataFromShared(String sharedKey, String key, Context context) {

    SharedPreferences sharedPreferences = context.getSharedPreferences(sharedKey, Context.MODE_PRIVATE);

    return sharedPreferences.getInt(key, 0);
}

From source file:Main.java

public static void saveConfigServidor(String login, String senha, String url, Context context) {

    SharedPreferences.Editor editor = context.getSharedPreferences("RestService", Context.MODE_PRIVATE).edit();
    editor.putString("login", login);
    editor.putString("senha", senha);
    editor.putString("url", url);
    editor.commit();//from  ww  w.  j a  v a 2 s.  com
}

From source file:Main.java

public static String readWLPref(Context context, String prefName) {
    SharedPreferences prefs = context.getSharedPreferences("WLPrefs", 0);
    return prefs.getString(prefName, null);
}