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 getLoginUserPasswd(Context context) {

    SharedPreferences preferences = context.getSharedPreferences(XL_PREFERENCES, Context.MODE_PRIVATE);
    return preferences.getString("loginUserPasswd", "");
}

From source file:Main.java

static public int getIntegerPreferences(Context context, String key) {
    SharedPreferences pref = context.getSharedPreferences("pref", Context.MODE_PRIVATE);
    return pref.getInt(key, 0);
}

From source file:Main.java

public static boolean isPasscodeSet(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);

    if (prefs.getString(PREFS_KEY_PASSCODE, null) != null)
        return true;
    else//from w  w  w  . jav a2 s  . c  o  m
        return false;
}

From source file:Main.java

public static String getStringFromCache(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    String string = sp.getString(key, "");
    return string;
}

From source file:Main.java

public static boolean getBoolean(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences("atguigu", Context.MODE_PRIVATE);
    return sp.getBoolean(key, false);
}

From source file:Main.java

public static String getString(Context context, String title) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    return sp.getString(title, "");
}

From source file:Main.java

public static String getLAT(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(LAT, Context.MODE_PRIVATE);
    String city = preferences.getString(CVALUE, "40.017349");
    return city;//w w w  .  ja  v  a2s  . c  om
}

From source file:Main.java

public static String getLNG(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(LNG, Context.MODE_PRIVATE);
    String city = preferences.getString(CVALUE, "116.40712");
    return city;//from  w ww  .j a va 2s  . c  o m
}

From source file:Main.java

public static Set<String> getAllPersonIds(String personGroupId, Context context) {
    SharedPreferences personIdSet = context.getSharedPreferences(personGroupId + "PersonIdSet",
            Context.MODE_PRIVATE);
    return personIdSet.getStringSet("PersonIdSet", new HashSet<String>());
}

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;
}