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 getGcmKey(final Context context, final String accountName) {
    SharedPreferences sp = getSharedPreferences(context);
    String gcmKey = sp.getString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_GCM_KEY), null);

    // if there is no current GCM key, generate a new random one
    if (TextUtils.isEmpty(gcmKey)) {
        gcmKey = UUID.randomUUID().toString();
        Log.d("GoogleAcount",
                "No GCM key on account " + accountName + ". Generating random one: " + sanitizeGcmKey(gcmKey));
        setGcmKey(context, accountName, gcmKey);
    }/*from  www .  ja  v a  2 s . c o  m*/

    return gcmKey;
}

From source file:org.structr.android.restclient.StructrConnector.java

private static void updatePreferences(SharedPreferences prefs) {
    server = prefs.getString(SERVER_KEY, "");
    userName = prefs.getString(USERNAME_KEY, "");
    password = prefs.getString(PASSWORD_KEY, "");
}

From source file:Main.java

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

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_PLUS_COVER_URL), null)
            : null;//  w w  w.j ava 2  s  .  c om
}

From source file:Main.java

/**
 * Gets the stored authToken, which may be expired
 *//*  ww  w  .  j  a v a 2 s .  co  m*/
public static String GetAuthToken(Context applicationContext) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext);
    return prefs.getString("GDOCS_AUTH_TOKEN", "");
}

From source file:Main.java

public static String getPlusProfileId(final Context context) {
    SharedPreferences sp = getSharedPreferences(context);
    return hasActiveAccount(context)
            ? sp.getString(makeAccountSpecificPrefKey(context, PREFIX_PREF_PLUS_PROFILE_ID), null)
            : null;/*from   w  ww .j a v a2s.c o  m*/
}

From source file:Main.java

public static Boolean isEnoughtBattery(Context context) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    Float acceptableBatteryLevel = Float.parseFloat(pref.getString("pref_battery_level", "40.0f"));
    Float batteryLevel = getBatteryLevel(context);

    return (batteryLevel >= acceptableBatteryLevel || isCharging(context));
}

From source file:Main.java

public static Map<String, String> getData(SharedPreferences sp, String[] keys) {
    Map<String, String> map = new HashMap<String, String>();
    for (String key : keys) {
        map.put(key, sp.getString(key, ""));
    }//from w  w  w.  j  ava2s.  c  o  m
    return map;
}

From source file:Main.java

@SuppressLint("SetJavaScriptEnabled")
public static void webView_Settings(final Activity from, final WebView webView) {

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);
    String fontSizeST = sharedPref.getString("font", "100");
    int fontSize = Integer.parseInt(fontSizeST);

    webView.getSettings().setAppCachePath(from.getApplicationContext().getCacheDir().getAbsolutePath());
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setTextZoom(fontSize);
    webView.getSettings().setGeolocationEnabled(false);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default
}

From source file:Main.java

public static Object getParam(Context context, String key, Object defaultObject) {
    String type = defaultObject.getClass().getSimpleName();
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);

    if ("String".equals(type)) {
        return sp.getString(key, (String) defaultObject);
    } else if ("Integer".equals(type)) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if ("Boolean".equals(type)) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if ("Float".equals(type)) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if ("Long".equals(type)) {
        return sp.getLong(key, (Long) defaultObject);
    }//from   w  w  w.j av  a2 s. co m
    return null;
}