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:com.batontouch.facebook.SessionStore.java

public static boolean restore(Facebook session, Context context) {
    mcontext = context;/*from ww w .  j av  a2  s . com*/
    SharedPreferences savedSession = context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
    session.setAccessToken(savedSession.getString(TOKEN, null));
    session.setAccessExpires(savedSession.getLong(EXPIRES, 0));
    return session.isSessionValid();
}

From source file:com.gadelkareem.serverload.ServerLoadConfig.java

static String loadPref(Context context, int appWidgetId, String type) {
    SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
    String result = prefs.getString(PREF_PREFIX_KEY + type + appWidgetId, null);

    if (result != null) {
        return result;
    } else {//from w  w  w.j a  v  a  2s.c om
        return "";
    }
}

From source file:com.nloko.android.syncmypix.facebook.FacebookSyncService.java

public static boolean isLoggedIn(Context context) {
    SharedPreferences settings = context.getSharedPreferences(SettingsActivity.PREFS_NAME, 0);
    String session_key = settings.getString("session_key", null);
    String secret = settings.getString("secret", null);
    String uid = settings.getString("uid", null);

    return session_key != null && secret != null && uid != null;
}

From source file:com.apptentive.android.sdk.storage.DeviceManager.java

public static Device getStoredDevice(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    String deviceString = prefs.getString(Constants.PREF_KEY_DEVICE, null);
    try {/*from w ww.j a v a2 s  .c o m*/
        return new Device(deviceString);
    } catch (Exception e) {
        // Ignore
    }
    return null;
}

From source file:cm.aptoide.pt.util.NetworkUtils.java

public static String getUserAgentString(Context mctx) {
    SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mctx);
    String myid = sPref.getString("myId", "NoInfo");
    String myscr = sPref.getInt("scW", 0) + "x" + sPref.getInt("scH", 0);
    String partnerid = "";
    if (ApplicationAptoide.PARTNERID != null) {
        partnerid = "PartnerID:" + ApplicationAptoide.PARTNERID + ";";
    }//from  w  w w. ja  v a2 s  .c  om

    return "aptoide-" + mctx.getString(R.string.ver_str) + ";" + Configs.TERMINAL_INFO + ";" + myscr + ";id:"
            + myid + ";" + sPref.getString(Configs.LOGIN_USER_LOGIN, "") + ";" + partnerid;
}

From source file:com.sublimis.urgentcallfilter.MyPreference.java

private static String getStringPref(int prefKeyResId, String defaultValue) {
    String prefKey = getStringResource(prefKeyResId);
    SharedPreferences sharedPrefs = getPrefs();

    if (sharedPrefs != null)
        return sharedPrefs.getString(prefKey, defaultValue);
    else//from  www  .j  a v  a 2 s  .co  m
        return defaultValue;
}

From source file:com.makotosan.vimeodroid.Authentication.java

public static boolean isUserLoggedIn(Context context, Application app) {
    // Check if we have saved credentials
    final SharedPreferences myPrefs = context.getSharedPreferences(Authentication.MY_PREFS,
            Context.MODE_PRIVATE);
    final String authToken = myPrefs.getString(Authentication.CONSUMER_TOKEN_PREF, null);

    // If not, return false
    if (authToken == null || authToken.length() == 0) {
        return false;
    }/*from www.ja  va 2 s  .com*/

    if (getUser(context, app) == null) {
        return false;
    }

    return true;
}

From source file:com.apptentive.android.sdk.storage.DeviceManager.java

public static CustomData loadCustomDeviceData(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    String deviceDataString = prefs.getString(Constants.PREF_KEY_DEVICE_DATA, null);
    try {//from   w w w  .ja v a2  s .  c  o m
        return new CustomData(deviceDataString);
    } catch (Exception e) {
        // Ignore
    }
    try {
        return new CustomData();
    } catch (JSONException e) {
        // Ignore
    }
    return null; // This should never happen.
}

From source file:com.geotrackin.gpslogger.senders.osm.OSMHelper.java

public static boolean IsOsmAuthorized(Context ctx) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String oAuthAccessToken = prefs.getString("osm_accesstoken", "");

    return (oAuthAccessToken != null && oAuthAccessToken.length() > 0);
}

From source file:Main.java

public static HashMap<String, String> restoreDistanceAndLocation(Context context) {
    SharedPreferences sharedPref = context.getSharedPreferences("DistanceAndLocation", Context.MODE_PRIVATE);
    String[] keyList = { "longitude", "latitude", "kmTravelled" };
    HashMap<String, String> values = new HashMap<>();
    for (String key : keyList)
        values.put(key, sharedPref.getString(key, null));
    return values;
}