List of usage examples for android.content SharedPreferences getString
@Nullable String getString(String key, @Nullable String defValue);
From source file:Main.java
public static Object getSp(Context context, String key, Object defaultObject) { String type = defaultObject.getClass().getSimpleName(); String packageName = context.getPackageName(); SharedPreferences sp = context.getSharedPreferences(packageName, 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); }// w ww . ja v a 2 s . c o m return null; }
From source file:Main.java
public static void reloadLocale(Context context) { SharedPreferences sharedPrefs = PreferenceManager .getDefaultSharedPreferences(context.getApplicationContext()); String lang = sharedPrefs.getString(PREF_APP_LANGUAGE, Locale.getDefault().getLanguage()); if (sharedPrefs.getString(PREF_APP_LANGUAGE, "").equalsIgnoreCase("")) { sharedPrefs.edit().putString(PREF_APP_LANGUAGE, lang).commit(); }//from w w w . j a va2 s . c o m Configuration newConfig = context.getResources().getConfiguration(); if (!newConfig.locale.getLanguage().equals(lang)) { locale = new Locale(lang); } if (locale != null) { Locale.setDefault(locale); newConfig.locale = locale; context.getResources().updateConfiguration(newConfig, context.getResources().getDisplayMetrics()); } }
From source file:Main.java
public static RSAPublicKeySpec getRecipientsPublicKey(String contactNum, Context context) { Log.w(TAG, "retrieving public key for contact " + contactNum); SharedPreferences prefs = context.getSharedPreferences(contactNum, Context.MODE_PRIVATE); String pubMod = prefs.getString(PREF_PUBLIC_MOD, DEFAULT_PREF); String pubExp = prefs.getString(PREF_PUBLIC_EXP, DEFAULT_PREF); Log.w(TAG, "the public modulus is " + pubMod + " and exponent is " + pubExp + " for " + contactNum); // String recipient = prefs.getString(PREF_RECIPIENT_NUM, DEFAULT_PREF); if (!pubMod.isEmpty() && !pubExp.isEmpty()) { Log.i(TAG, "great! public key found for " + contactNum + " with modulus " + pubMod + " and exponent " + pubExp);/*from www .j a va 2 s .c o m*/ byte[] pubModBA = Base64.decode(pubMod, Base64.DEFAULT); byte[] pubExpBA = Base64.decode(pubExp, Base64.DEFAULT); BigInteger pubModBI = new BigInteger(1, pubModBA); // 1 is added as // an attempt to // deal with // com.android.org.bouncycastle.crypto.DataLengthException: // input too // large for RSA // cipher BigInteger pubExpBI = new BigInteger(1, pubExpBA); Log.i(TAG, "public modulus is " + pubModBI + " and public exponent is " + pubExpBI + " in base 256 " + pubModBA + " " + pubExpBA); // do I need to catch any exception for the following? RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(pubModBI, pubExpBI); // X509EncodedKeySpec publicKeySpec = new // X509EncodedKeySpec(encodedKey); return pubKeySpec; } Log.w(TAG, "recipient's public key not found"); return null; }
From source file:Main.java
public static String getAndClearDataNotSent(Context context) { synchronized (syncObject) { SharedPreferences settings = context.getSharedPreferences(BCB_UPDATES_SHARED_PREF, Context.MODE_PRIVATE); String strData = settings.getString(BCB_DATA_NOT_SENT, null); SharedPreferences.Editor editor = settings.edit(); editor.putString(BCB_DATA_NOT_SENT, ""); editor.commit();// w w w. j ava2 s .co m return strData; } }
From source file:Main.java
/** * getKalturaDomain returns the current domain. This function strips off all trailing / characters and the protocol. * @link APIHelpers.loadProtocol(context) * @param context/*from ww w . j a v a 2 s . co m*/ * @return */ public static String getKalturaDomain(Context context) { if (context == null) { return ""; } SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); String domain = sharedPreferences.getString(SHARED_PREFERENCES_KALTURA_DOMAIN, ""); while (domain != null && domain.endsWith("/")) { domain = domain.substring(0, domain.length() - 1); } return domain; }
From source file:Main.java
private static UUID getUuid(Context c) { final SharedPreferences prefs = c.getSharedPreferences(ID_PREFS_FILE, Context.MODE_PRIVATE); final String id = prefs.getString(ID_PREFS_DEVICE_ID, null); final UUID uuid; if (id != null) { uuid = UUID.fromString(id); } else {// w w w . j av a 2s . c om final String androidId = Secure.getString(c.getContentResolver(), Secure.ANDROID_ID); try { if (!BAD_UUID.equals(androidId)) { uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8")); } else { final String deviceId = ((TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE)) .getDeviceId(); if (deviceId != null) uuid = UUID.nameUUIDFromBytes(deviceId.getBytes("utf8")); else uuid = UUID.randomUUID(); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } prefs.edit().putString(ID_PREFS_DEVICE_ID, uuid.toString()).commit(); } return uuid; }
From source file:Main.java
/** * Get the shared preference about knn from localization method. * * @param context The calling context./*from w w w . j a v a 2 s .c o m*/ * @return Integer from preferences. If not a number, return value will be 3. */ public static int getPrefKnn(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); int value = 3; try { value = Integer.valueOf(sharedPreferences.getString("localization_knn", "3")); } catch (NumberFormatException e) { e.printStackTrace(); } return value; }
From source file:me.qisthi.cuit.helper.StorageHelper.java
public static String getPreferenceStringValue(Activity activity, String key) { SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE); return sharedPreferences.getString(key, ""); }
From source file:Main.java
public static String getStringPref(Context context, String key) { String value = null;/* ww w . jav a 2 s. com*/ if (!isEmpty(key)) { SharedPreferences shareConfig = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); if (null != shareConfig) { value = shareConfig.getString(key, null); } } return value; }
From source file:com.browsertophone.DeviceRegistrar.java
private static HttpResponse makeRequest(Context context, String deviceRegistrationID, String urlPath) throws Exception { SharedPreferences settings = Prefs.get(context); String accountName = settings.getString("accountName", null); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("devregid", deviceRegistrationID)); String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); if (deviceId != null) { params.add(new BasicNameValuePair("deviceId", deviceId)); }// w ww . j a va2s . c o m AppEngineClient client = new AppEngineClient(context, accountName); return client.makeRequest(urlPath, params); }