Example usage for android.content Context MODE_PRIVATE

List of usage examples for android.content Context MODE_PRIVATE

Introduction

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

Prototype

int MODE_PRIVATE

To view the source code for android.content Context MODE_PRIVATE.

Click Source Link

Document

File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).

Usage

From source file:Main.java

public static void isOpen(final Context mContext, final boolean isOpen) {
    SharedPreferences preferences = mContext.getSharedPreferences("com.livechat.chat_open",
            Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putBoolean("isOpen", isOpen);
    editor.commit();//  w  w  w  .  j  a va  2  s.  co m
}

From source file:Main.java

public static <T> T getData(Context context, String fileName, String key, Class T) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    T result;/*from   ww w  . ja v a2 s  .c  o m*/
    if (String.class.isAssignableFrom(T)) {
        result = (T) sharedPreferences.getString(key, "");
    } else if (Integer.class.isAssignableFrom(T)) {
        result = (T) Integer.valueOf(sharedPreferences.getInt(key, 0));
    } else if (Float.class.isAssignableFrom(T)) {
        result = (T) Float.valueOf(sharedPreferences.getFloat(key, 0));
    } else if (Long.class.isAssignableFrom(T)) {
        result = (T) Long.valueOf(sharedPreferences.getLong(key, 0));
    } else {
        result = (T) Boolean.valueOf(sharedPreferences.getBoolean(key, false));
    }
    return result;
}

From source file:Main.java

public static void putInt(Context context, String key, int value) {
    if (sp == null) {
        sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    }/*from  ww  w.j  a  va  2s  . c om*/
    sp.edit().putInt(key, value).commit();
}

From source file:Main.java

public static void setBoolean(Context ctx, String key, boolean value) {
    SharedPreferences spf = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    spf.edit().putBoolean(key, value).apply();
}

From source file:Main.java

public static void setInt(Context context, String key, int values) {
    if (sp == null) {
        sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    }//  w  w w . j  a  v  a 2 s  . c o m
    sp.edit().putInt(key, values).apply();
}

From source file:Main.java

public static Object getData(Context context, String fileName, String key, Class clazz) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    if (clazz.getName().equals(String.class.getName())) {
        return sharedPreferences.getString(key, "");
    } else if (clazz.getName().equals(Integer.class.getName())) {
        return sharedPreferences.getInt(key, 0);
    } else if (clazz.getName().equals(Float.class.getName())) {
        return sharedPreferences.getFloat(key, 0);
    } else if (clazz.getName().equals(Long.class.getName())) {
        return sharedPreferences.getLong(key, 0);
    } else {// w  ww  .  j a v a  2  s  . c o  m
        return sharedPreferences.getBoolean(key, false);
    }
}

From source file:Main.java

public static void saveProperty(final Context context, String propertyName, int propertyValue) {
    SharedPreferences preferences = context.getSharedPreferences("YTWPreferences", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putInt(propertyName, propertyValue);
    editor.commit();/*from  ww w .  j av a2  s .  com*/
}

From source file:Main.java

public static boolean getBoolean(Context context, String key) {

    if (sp == null) {
        sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    }//www . j a  va 2s  .c om
    return sp.getBoolean(key, false);

}

From source file:Main.java

public static void putInt(Context mContext, String key, int values) {
    SharedPreferences sp = mContext.getSharedPreferences(SHARE_NAME, Context.MODE_PRIVATE);
    sp.edit().putInt(key, values).commit();
}

From source file:Main.java

public static String getString(Context context, String key) {
    SharedPreferences preferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);

    return preferences.getString(key, "");
}