List of usage examples for android.content SharedPreferences getString
@Nullable String getString(String key, @Nullable String defValue);
From source file:Main.java
public static String getPrefString(Context context, int keyId, int defaultValueId) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); String key = context.getString(keyId); String defaultValue = context.getString(defaultValueId); return sharedPreferences.getString(key, defaultValue); }
From source file:com.uwetrottmann.movies.getglueapi.GetGlue.java
public static boolean isAuthenticated(final SharedPreferences prefs) { String token = prefs.getString(OAUTH_TOKEN, ""); String secret = prefs.getString(OAUTH_TOKEN_SECRET, ""); if (token == "" || secret == "") { return false; }//w ww . jav a 2 s. c om return true; }
From source file:fr.shywim.antoinedaniel.utils.GcmUtils.java
public static String getRegistrationId(Context context) { final SharedPreferences prefs = context.getSharedPreferences(AppConstants.GOOGLE_PREFS, Context.MODE_PRIVATE); String registrationId = prefs.getString(AppConstants.GOOGLE_GCM_REGID, ""); if (registrationId.isEmpty()) { return ""; }/*w w w.ja v a 2 s . c o m*/ // Check if app was updated; if so, it must clear the registration ID // since the existing regID is not guaranteed to work with the new // app version. int registeredVersion = prefs.getInt(AppConstants.GOOGLE_GCM_APPVER, Integer.MIN_VALUE); int currentVersion = Utils.getAppVersion(context); if (registeredVersion != currentVersion) { return ""; } return registrationId; }
From source file:Main.java
public static ArrayList<String> loadSavedCityList(Context c) { ArrayList<String> list = new ArrayList<String>(); SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); int cityNum = preferences.getInt(PREF_KEPT_CITY_NUM_KEY, 0); for (int i = 0; i < cityNum; i++) { String keptCity = preferences.getString(PREF_KEPT_CITY_ITEM_BASE + (i + 1), ""); if (!TextUtils.isEmpty(keptCity)) { list.add(keptCity);//from www . j a v a2s . c o m } } return list; }
From source file:edu.stanford.mobisocial.dungbeetle.social.FriendRequest.java
private static Uri getInvitationUri(Context c, boolean appendCapability) { SharedPreferences p = c.getSharedPreferences("main", 0); String cap = p.getString(PREF_FRIEND_CAPABILITY, null); if (cap == null) { String capability = App.instance().getRandomString(); p.edit().putString(PREF_FRIEND_CAPABILITY, capability).commit(); cap = capability;// w w w.j a v a 2 s. c om } DBHelper helper = DBHelper.getGlobal(c); IdentityProvider ident = new DBIdentityProvider(helper); try { // String name = ident.userName(); String email = ident.userEmail(); String name = ident.userName(); PublicKey pubKey = ident.userPublicKey(); helper.close(); Uri.Builder builder = new Uri.Builder().scheme("http").authority("mobisocial.stanford.edu") .path("musubi/join").appendQueryParameter("name", name).appendQueryParameter("email", email) .appendQueryParameter("publicKey", DBIdentityProvider.publicKeyToString(pubKey)); if (appendCapability) { builder.appendQueryParameter("cap", cap); } return builder.build(); } finally { ident.close(); } }
From source file:com.emacs.xpets.utils.Utils.java
public static String getMachineKey(Context context) { String value = System.getProperty(Constants.MACHINE_KEY); if (value == null) { SharedPreferences sp = context.getSharedPreferences(Constants.MACHINE_KEY, Context.MODE_PRIVATE); value = sp.getString(Constants.MACHINE_KEY, null); if (value == null) { value = UUID.randomUUID().toString(); Editor editor = sp.edit();/*from w ww . j a v a 2 s . c o m*/ editor.putString(Constants.MACHINE_KEY, value); editor.commit(); } System.setProperty(Constants.MACHINE_KEY, value); } return value; }
From source file:com.apptentive.android.sdk.storage.PersonManager.java
public static Person getStoredPerson(Context context) { SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE); String PersonString = prefs.getString(Constants.PREF_KEY_PERSON, null); try {/*w w w .j ava 2 s. c o m*/ return new Person(PersonString); } catch (Exception e) { // Ignore } return null; }
From source file:Main.java
/** * Gets an enum value in the SharedPreference. * * @param sharedPreference a {@link SharedPreferences} to be loaded. * @param key a key name/*from ww w . j av a 2s .c o m*/ * @param type a class of enum value * @param defaultValue default value if the {@link SharedPreferences} doesn't have corresponding * entry. * @param conversionRecoveryValue default value if unknown value is stored. * For example, if the value is "ALPHA" and {@code type} doesn't have "ALPHA" entry, * this argument is returned. */ public static <T extends Enum<T>> T getEnum(SharedPreferences sharedPreference, String key, Class<T> type, T defaultValue, T conversionRecoveryValue) { if (sharedPreference == null) { return defaultValue; } String name = sharedPreference.getString(key, null); if (name != null) { try { return Enum.valueOf(type, name); } catch (IllegalArgumentException e) { return conversionRecoveryValue; } } return defaultValue; }
From source file:com.apptentive.android.sdk.model.Configuration.java
public static Configuration load(SharedPreferences prefs) { String json = prefs.getString(Constants.PREF_KEY_APP_CONFIG_JSON, null); try {//from w ww .ja v a2 s . c om if (json != null) { return new Configuration(json); } } catch (JSONException e) { Log.e("Error loading Configuration from SharedPreferences.", e); } return new Configuration(); }
From source file:edu.stanford.mobisocial.dungbeetle.social.FriendRequest.java
public static long acceptFriendRequest(Context c, Uri friendRequest, boolean requireCapability) { String email = friendRequest.getQueryParameter("email"); String name = friendRequest.getQueryParameter("name"); if (name == null) { name = email;/*from w ww.j a va 2 s .c o m*/ } String pubKeyStr = friendRequest.getQueryParameter("publicKey"); RSACrypto.publicKeyFromString(pubKeyStr); // may throw exception String cap = friendRequest.getQueryParameter("cap"); if (requireCapability) { if (cap == null) { Log.w(TAG, "Unapproved friend request"); return -1; } SharedPreferences p = c.getSharedPreferences("main", 0); String myCap = p.getString(PREF_FRIEND_CAPABILITY, null); if (myCap == null) { Log.w(TAG, "No capability available"); return -1; } if (!cap.equals(myCap)) { Log.w(TAG, "Capability mismatch"); return -1; } } Uri uri = Helpers.insertContact(c, pubKeyStr, name, email); long contactId = Long.valueOf(uri.getLastPathSegment()); Helpers.insertSubscriber(c, contactId, "friend"); return contactId; }