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 int getCount(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(DOWN_COUNT, Context.MODE_PRIVATE);
    int count = preferences.getInt(DOWN_COUNT_KEY, 0);
    return count;
}

From source file:Main.java

private static SharedPreferences getPreferences(Context context) {
    if (sp == null) {
        sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    }//from  w ww .  ja  va  2  s.co m

    return sp;
}

From source file:Main.java

public static void saveStringData(Context context, String key, String value) {

    if (sharedPreferences == null) {
        sharedPreferences = context.getSharedPreferences(CONFIG, Context.MODE_PRIVATE);
    }//from   w  ww  .j  a v  a  2 s .  co m
    sharedPreferences.edit().putString(key, value).commit();
}

From source file:Main.java

public static void putVersion(Context context, String version) {
    SharedPreferences preferences = context.getSharedPreferences(VERSION, Context.MODE_PRIVATE);
    preferences.edit().putString(VERSION_KEY, version).commit();
}

From source file:Main.java

public static String getDeviceId(Context context) {
    SharedPreferences mPrefs = context.getSharedPreferences(DEVICE_ID_FILE, Context.MODE_PRIVATE);
    return mPrefs.getString(DEVICE_ID_KEY, null);
}

From source file:Main.java

public static void putBooleanShareData(String key, boolean value) {
    SharedPreferences sp = mContext.getSharedPreferences(KEY, Context.MODE_PRIVATE);
    Editor et = sp.edit();/*w w w.  j av  a2  s.c  o m*/
    et.putBoolean(key, value);
    et.commit();
}

From source file:Main.java

public static void writeToFile(Context context, String file, String content) throws IOException {
    FileOutputStream fos = context.openFileOutput(file, Context.MODE_PRIVATE);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
    bw.write(content);/*w w w .ja v  a 2s . c  om*/
    bw.flush();
    bw.close();
    fos.close();
}

From source file:Main.java

public static void cacheOnlyDestop(Context context, boolean onlyDestop) {
    SharedPreferences sp = context.getSharedPreferences(CONFIG, Context.MODE_PRIVATE);
    sp.edit().putBoolean(KEY_ONLY_DESTOP, onlyDestop).commit();
}

From source file:Main.java

static int loadLastPhoneCount(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(AGE_PREFERENCES, Context.MODE_PRIVATE);

    return prefs.getInt(AGE_LAST_PHONE_COUNT, -1);
}