List of usage examples for android.content SharedPreferences getString
@Nullable String getString(String key, @Nullable String defValue);
From source file:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java
/** * Retrieve String information into SharedPreferences * @param context/*from ww w . j ava2 s. co m*/ * @param key * @param dftValue * @return */ public static String getValue(Context context, String key, String dftValue) { SharedPreferences pref = context.getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, Activity.MODE_PRIVATE); try { return pref.getString(key, dftValue); } catch (Exception e) { return dftValue; } }
From source file:com.hoccer.api.android.AsyncLinccer.java
public static PrivateKey getPrivateKeyFromSharedPreferences(Context context) throws IOException, InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException { SharedPreferences prefs = context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE); String defaultValue = ""; String storedValue = prefs.getString(PREF_PRIVATE_KEY, defaultValue); Log.v(LOG_TAG, "getPrivateKeyFromSharedPreferences, storedValue=" + storedValue); byte[] myEncodedPrivateKey = Base64.decode(storedValue); PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(CryptoHelper.wrapRSA1024_PKCS8(myEncodedPrivateKey)); KeyFactory kf = KeyFactory.getInstance("RSA"); PrivateKey myPrivateKey = kf.generatePrivate(privSpec); return myPrivateKey; }
From source file:com.microsoft.activitytracker.Core.NetworkCalls.java
/*** * Use this method when you want to make a get call to the oData endpoint NOTE: if you are trying to hit the get endpoint, unlike usual * this endpoint does restrict you to ONLY get calls * @param thisContext the context that you are making this call from * @param path the path to add to your current endpoint * @param queries map of the parameters to use in the query string * @param callback the callback that will be invoked when the network call is finished *//* www . j a va 2s .c o m*/ public static void oDataGetRequest(Context thisContext, String path, Map<String, String> queries, Callback<LinkedTreeMap<String, Object>> callback) { SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(thisContext); RestAdapter restAdapter = new RestAdapter.Builder() // .setLogLevel(RestAdapter.LogLevel.FULL) .setConverter(new GsonConverter(new Gson())).setEndpoint(appPrefs.getString(Constants.ENDPOINT, "")) .setRequestInterceptor(ActivityTracker.getRequestInterceptor()).build(); CrmService crmService = restAdapter.create(CrmService.class); crmService.makeoDataGet(path, queries, callback); }
From source file:com.microsoft.activitytracker.Core.NetworkCalls.java
/*** * Use this method when you want to post to the odata endpoint (Means you have a body to your request) * @param thisContext the context that you are making this call from * @param body the body of the network call you want to send to the oData endpoint * @param path the path to add to your current endpoint * @param callback the callback that will be invoked when the network call is finished *//*www . j av a2s. c o m*/ public static void oDataPostRequest(Context thisContext, String body, String path, Callback<LinkedTreeMap<String, Object>> callback) { SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(thisContext); RestAdapter restAdapter = new RestAdapter.Builder() // .setLogLevel(RestAdapter.LogLevel.FULL) .setConverter(new GsonConverter(new Gson())).setEndpoint(appPrefs.getString(Constants.ENDPOINT, "")) .setRequestInterceptor(ActivityTracker.getRequestInterceptor()).build(); CrmService crmService = restAdapter.create(CrmService.class); crmService.makeoDataPost(path, new TypedString(body), callback); }
From source file:com.google.android.gcm.GCMRegistrar.java
/** * Sets the registration id in the persistence store. * * @param context application's context. * @param regId registration id/*from w w w. j a v a 2s. c om*/ */ static String setRegistrationId(Context context, String regId) { final SharedPreferences prefs = getGCMPreferences(context); String oldRegistrationId = prefs.getString(PROPERTY_REG_ID, ""); int appVersion = getAppVersion(context); Log.v(TAG, "Saving regId on app version " + appVersion); Editor editor = prefs.edit(); editor.putString(PROPERTY_REG_ID, regId); editor.putInt(PROPERTY_APP_VERSION, appVersion); editor.commit(); return oldRegistrationId; }
From source file:com.google.android.gcm.GCMRegistrar.java
/** * Gets the current registration id for application on GCM service. * <p>/*from w ww . jav a 2 s .c o m*/ * If result is empty, the registration has failed. * * @return registration id, or empty string if the registration is not * complete. */ public static String getRegistrationId(Context context) { final SharedPreferences prefs = getGCMPreferences(context); String registrationId = prefs.getString(PROPERTY_REG_ID, ""); // check if app was updated; if so, it must clear registration id to // avoid a race condition if GCM sends a message int oldVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE); int newVersion = getAppVersion(context); if (oldVersion != Integer.MIN_VALUE && oldVersion != newVersion) { Log.v(TAG, "App version changed from " + oldVersion + " to " + newVersion + "; resetting registration id"); clearRegistrationId(context); registrationId = ""; } return registrationId; }
From source file:com.example.android.sunshine.app.Utility.java
public static String getPreferredLocation(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return prefs.getString(context.getString(R.string.pref_location_key), context.getString(R.string.pref_location_default)); }
From source file:com.example.android.sunshine.app.Utility.java
public static boolean isMetric(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return prefs/*from ww w.ja va 2 s . com*/ .getString(context.getString(R.string.pref_units_key), context.getString(R.string.pref_units_metric)) .equals(context.getString(R.string.pref_units_metric)); }