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 float readFloat(Context context, String key, float defaultValue) {
    SharedPreferences pre = context.getSharedPreferences(STORE_NAME, Context.MODE_PRIVATE);
    return pre.getFloat(STORE_KEY_PREFIX + key, defaultValue);
}

From source file:Main.java

public static String getDeviceId(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(DEVICE, Context.MODE_PRIVATE);
    String deviceid = preferences.getString(DEVICEID, "android");
    return deviceid;
}

From source file:Main.java

public static void increment(Context context, String key, int amount) {
    SharedPreferences sp = context.getSharedPreferences(DEFAULT_FILE_NAME, Context.MODE_PRIVATE);
    int count = sp.getInt(key, -1);
    if (count == -1)
        count = 0;//from   w  w  w.j  a v  a 2 s.  c  om
    count++;
    SharedPreferences.Editor editor = context.getSharedPreferences(DEFAULT_FILE_NAME, Context.MODE_PRIVATE)
            .edit();
    editor.putInt(key, count);
    editor.commit();
}

From source file:Main.java

public static boolean isFirstStart(Context context) {

    Log.e("jhd", "SharedUtils-isFirstStart   :  "
            + context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE).getBoolean(MODE_NAME, true));
    return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE).getBoolean(MODE_NAME, true);

}

From source file:Main.java

public static void putString(Context context, String key, String value) {
    SharedPreferences sp = context.getApplicationContext().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    Editor editor = sp.edit();/*from www  .  j  a  v a  2s  .co m*/
    editor.putString(key, value);
    editor.commit();
}

From source file:Main.java

public static void setBooleanPref(Context context, String name, boolean value) {
    SharedPreferences prefs = context.getSharedPreferences(APPLICATION_NAME, Context.MODE_PRIVATE);
    Editor ed = prefs.edit();/*from w  w  w. ja v  a2 s .co m*/
    ed.putBoolean(name, value);
    ed.commit();
}

From source file:Main.java

public static boolean getIsOpenFirst(Context context) {
    if (sharedPreferences == null) {
        sharedPreferences = context.getSharedPreferences("led", Context.MODE_PRIVATE);
        return true;
    }// w  w w  .ja  v a 2s.c  om

    sharedPreferences.getString("led", null);
    return false;
}

From source file:Main.java

public static boolean isOnlyDestop(Context context) {
    SharedPreferences sp = context.getSharedPreferences(CONFIG, Context.MODE_PRIVATE);
    return sp.getBoolean(KEY_ONLY_DESTOP, false);
}

From source file:Main.java

public static void saveBooleanPreferences(String key, boolean value, Context ctx) {
    SharedPreferences sp = ctx.getSharedPreferences(sharedPrefsFile, Context.MODE_PRIVATE);
    Editor edit = sp.edit();// w ww  .j a va  2s .  c  o  m
    edit.putBoolean(key, value);
    edit.commit();
}

From source file:Main.java

public static void putBoolean(Context context, String key, boolean value) {
    SharedPreferences sp = context.getApplicationContext().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    Editor editor = sp.edit();//from ww w  .  j a v a  2 s .  co m
    editor.putBoolean(key, value);
    editor.commit();
}