Example usage for android.content SharedPreferences getString

List of usage examples for android.content SharedPreferences getString

Introduction

In this page you can find the example usage for android.content SharedPreferences getString.

Prototype

@Nullable
String getString(String key, @Nullable String defValue);

Source Link

Document

Retrieve a String value from the preferences.

Usage

From source file:Main.java

public static String getString(Context context, String key, String defaultValue) {
    SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
    return settings.getString(key, defaultValue);
}

From source file:Main.java

static public String readSharePerf(String tag) {
    SharedPreferences pref = activity.getSharedPreferences(tag, Context.MODE_PRIVATE);
    String data = pref.getString(tag, "");

    if (data.equalsIgnoreCase(""))
        return null;
    else//ww  w  .  ja  v a2 s .  co m
        return data;
}

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

public static String getIpPort(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(IP_PORT, Context.MODE_PRIVATE);
    String ip = preferences.getString(CVALUE, "121.41.112.232:9418");
    return ip;//from w  ww  .  j  a  v a  2 s . com
}

From source file:com.readystatesoftware.simpl3r.utils.SharedPreferencesUtils.java

public static ArrayList<String> getStringArrayPref(SharedPreferences prefs, String key) {
    String json = prefs.getString(key, null);
    ArrayList<String> values = new ArrayList<String>();
    if (json != null) {
        try {// w w  w .ja va  2 s .c om
            JSONArray a = new JSONArray(json);
            for (int i = 0; i < a.length(); i++) {
                String val = a.optString(i);
                values.add(val);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return values;
}

From source file:Main.java

public static String getWiFiConfigStatus(final Context context) {
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    return sp.getString(PREF_WIFI_AP_CONFIG, null);
}

From source file:Main.java

public static String getPreference(Context context, String key) {
    SharedPreferences prefs = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
    String value = prefs.getString(key, "");
    return value;
}

From source file:Main.java

public static String getPreferenceString(Context context, String preferenceKey) {
    String preferenceValue;// w w w .j av  a 2s.co m
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    preferenceValue = preferences.getString(preferenceKey, null);
    return preferenceValue;
}

From source file:Main.java

public static String getUserPic(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(USERPIC, Context.MODE_PRIVATE);
    String city = preferences.getString(CVALUE, "null");
    return city;//from  w w w  .  java 2 s  .  c o m
}

From source file:Main.java

public static String getUserPassword(Context context) {
    String upwd = "";
    SharedPreferences preferences = context.getSharedPreferences("UserInfo.txt", Context.MODE_PRIVATE);
    upwd = preferences.getString("upwd", "");
    return upwd;//from  w w  w .ja va2  s  .c o  m
}