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 isi;/*from  w  ww . java  2 s  .c  o m*/
    SharedPreferences sharedPreferences = context.getSharedPreferences("Zelory", Context.MODE_PRIVATE);
    isi = sharedPreferences.getString(key, null);
    return isi;
}

From source file:Main.java

public static String getDeviceId(Context context) {
    final String PREFS_DEVICE_ID = "prefs_device_id";
    final String PREF_DEVICE_ID = "device_id";
    SharedPreferences sp = context.getSharedPreferences(PREFS_DEVICE_ID, Context.MODE_PRIVATE);
    String deviceId = sp.getString(PREF_DEVICE_ID, null);
    if (deviceId == null) {
        deviceId = UUID.randomUUID().toString();
        sp.edit().putString(PREF_DEVICE_ID, deviceId).apply();
    }/*from ww  w.j  av a  2  s .  c o  m*/
    return deviceId;
}

From source file:Main.java

public static String getUserCidiograph(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(USER_INFO_OTHER, Context.MODE_PRIVATE);
    String userLevel = preferences.getString(USER_CIDIOGRAPH, "");
    return userLevel;
}

From source file:Main.java

public static String getUserDeposit(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(USER_INFO_OTHER, Context.MODE_PRIVATE);
    String userLevel = preferences.getString(USER_DEPOSIT, "");
    return userLevel;
}

From source file:Main.java

public static String getUserKbi(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(USER_INFO_OTHER, Context.MODE_PRIVATE);
    String userLevel = preferences.getString(USER_KBI, "");
    return userLevel;
}

From source file:Main.java

public static String getUserScore(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(USER_INFO_OTHER, Context.MODE_PRIVATE);
    String userLevel = preferences.getString(USER_SCORE, "");
    return userLevel;
}

From source file:Main.java

public static String getUserLevel(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(USER_INFO_OTHER, Context.MODE_PRIVATE);
    String userLevel = preferences.getString(USER_LEVEL, "");
    return userLevel;
}

From source file:Main.java

public static String getPreferences(Context context, String key, String defValue) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String savedPref = sharedPreferences.getString(key, defValue);
    return savedPref;
}

From source file:Main.java

/**
 * Gets the localization method from the shared preferences.
 *
 * @param context The calling context.//  ww  w.j a v a  2  s. com
 * @return int value, default 1 {@link com.indoor.navigation.indoornavigation.R.array#pref_loc_entries}.
 */
public static int getPrefPositioningMethod(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    return Integer.valueOf(sharedPreferences.getString("localization_type", "0"));
}

From source file:Main.java

public static String getString(Context context, String category, String key) {
    String defaultValue = "";
    try {/*w ww. java  2s .com*/
        SharedPreferences setMyPref = context.getSharedPreferences(category, Activity.MODE_WORLD_READABLE);
        return setMyPref.getString(key, defaultValue);
    } catch (Exception e) {
        Log.e(TAG, "Error when getString, return defaultValue " + defaultValue, e);
        return defaultValue;
    }
}