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 getWhitelist(SharedPreferences prefs, String languageCode) {
    if (languageCode.equals("deu")) {
        return prefs.getString(KEY_CHARACTER_WHITELIST_PAYMENT_SLIP, getDefaultWhitelist(languageCode));
    } else {/*from w ww  .  j  a va2  s.c  om*/
        throw new IllegalArgumentException();
    }
}

From source file:Main.java

public static String getPlusName(final Context context) {
    SharedPreferences sp = getSharedPreferences(context);
    return hasActiveAccount(context)
            ? sp.getString(makeAccountSpecificPrefKey(context, PREFIX_PREF_PLUS_NAME), null)
            : null;/*from w  w w. ja v a  2 s .  c  o m*/
}

From source file:Main.java

private static String getDeprecatedPreferencesAccessToken(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String token = prefs.getString(DEPRECATED_ACCESS_TOKEN_PREFERENCE, null);
    return token;
}

From source file:Main.java

public static String getPlusCoverUrl(final Context context) {
    SharedPreferences sp = getSharedPreferences(context);
    return hasActiveAccount(context)
            ? sp.getString(makeAccountSpecificPrefKey(context, PREFIX_PREF_PLUG_COVER_URL), null)
            : null;/*w  w w  .  j a  v a 2  s .  c  o m*/
}

From source file:Main.java

public static Calendar getWallpaperDate(Context context) {
    Calendar wallpaperDate = Calendar.getInstance();

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String dateTimeToString = preferences.getString("wallpaper_date", null);
    if (dateTimeToString == null)
        return wallpaperDate;

    wallpaperDate.set(Calendar.YEAR, Integer.parseInt(dateTimeToString.split("/")[0]));
    wallpaperDate.set(Calendar.MONTH, Integer.parseInt(dateTimeToString.split("/")[1]));
    wallpaperDate.set(Calendar.DATE, Integer.parseInt(dateTimeToString.split("/")[2]));

    return wallpaperDate;
}

From source file:Main.java

public static String getActiveAccountFullName(final Context context) {
    SharedPreferences sp = getSharedPreferences(context);
    return hasActiveAccount(context)
            ? sp.getString(makeAccountSpecificPrefKey(context, PREFIX_PREF_FULL_NAME), null)
            : null;/*  www . j a  v a2 s. c  o  m*/
}

From source file:Main.java

public static String getActiveAccountImgUrl(final Context context) {
    SharedPreferences sp = getSharedPreferences(context);
    return hasActiveAccount(context)
            ? sp.getString(makeAccountSpecificPrefKey(context, PREFIX_PREF_IMAGE_URL), null)
            : null;// www.  j ava  2s.  com
}

From source file:Main.java

/**
 * Generates a device ID.//ww w. j a  v a2 s  .  c o  m
 */
public synchronized static String getDeviceId(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String deviceId = preferences.getString("device_id", null);
    if (deviceId == null) {
        String chars = "123456789ABCDEFGHJKLMNPQRSTUVWXY";
        byte[] randomBytes = new byte[12];
        new SecureRandom().nextBytes(randomBytes);
        StringBuilder builder = new StringBuilder(12);
        for (int i = 0; i < 12; i++) {
            builder.append(chars.charAt((randomBytes[i] & 0xFF) % chars.length()));
        }
        deviceId = builder.toString();
        preferences.edit().putString("device_id", deviceId).apply();
    }
    return deviceId;
}

From source file:Main.java

public static String getActiveAccountTeamName(final Context context) {
    SharedPreferences sp = getSharedPreferences(context);
    return hasActiveAccount(context)
            ? sp.getString(makeAccountSpecificPrefKey(context, PREFIX_PREF_TEAM_NAME), "")
            : null;//from w  w  w.j a v  a 2s. com
}

From source file:Main.java

public static String getActiveAccountID(final Context context) {
    SharedPreferences sp = getSharedPreferences(context);
    return hasActiveAccount(context)
            ? sp.getString(makeAccountSpecificPrefKey(context, PREFIX_PREF_USER_ID), null)
            : null;/*  w  w w . j  a v a2  s .  c  o m*/
}