List of usage examples for android.os Bundle get
@Nullable
public Object get(String key)
From source file:com.idean.atthack.api.Param.java
/** * Util for logging bundle of params/* w ww . j a v a 2s. c o m*/ */ public static String toString(Bundle bundle) { StringBuffer b = new StringBuffer(); for (String key : bundle.keySet()) { b.append("[" + key + "] "); b.append(bundle.get(key) + ", "); } return b.toString(); }
From source file:com.deltadna.android.sdk.notifications.Utils.java
static String convert(Bundle payload) { final JSONObject result = new JSONObject(); for (final String key : payload.keySet()) { try {// w w w. ja va 2 s . co m if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { result.put(key, payload.get(key)); } else { result.put(key, JSONObject.wrap(payload.get(key))); } } catch (JSONException e) { Log.w(BuildConfig.LOG_TAG, e); } } return result.toString(); }
From source file:com.fanfou.app.opensource.util.IntentHelper.java
public static void logIntent(final String tag, final Intent intent) { if (intent == null) { return;//from w w w .j a va 2s . co m } final StringBuffer sb = new StringBuffer(); sb.append("\nAction:" + intent.getAction()); sb.append("\nData:" + intent.getData()); sb.append("\nDataStr:" + intent.getDataString()); sb.append("\nScheme:" + intent.getScheme()); sb.append("\nType:" + intent.getType()); final Bundle extras = intent.getExtras(); if ((extras != null) && !extras.isEmpty()) { for (final String key : extras.keySet()) { final Object value = extras.get(key); sb.append("\nEXTRA: {" + key + "::" + value + "}"); } } else { sb.append("\nNO EXTRAS"); } Log.i(tag, sb.toString()); }
From source file:Main.java
/** * Convert an Android bundle to a hashtable * @param bundle//w w w. java2 s .co m * @return */ public static Hashtable bundleToHashtable(Bundle bundle) { Hashtable retVal = new Hashtable(); Set<String> keys = bundle.keySet(); Iterator<String> iterator = keys.iterator(); String key; Object val; while (iterator.hasNext()) { key = iterator.next(); val = bundle.get(key); if (val instanceof String) { retVal.put(key, val); } else if (val instanceof Integer) { retVal.put(key, val); } } return retVal; }
From source file:Main.java
public static boolean bundleEquals(final Bundle bundle1, final Bundle bundle2) { if (bundle1 == null || bundle2 == null) return bundle1 == bundle2; final Iterator<String> keys = bundle1.keySet().iterator(); while (keys.hasNext()) { final String key = keys.next(); if (!objectEquals(bundle1.get(key), bundle2.get(key))) return false; }/*from ww w.j a va2 s .c o m*/ return true; }
From source file:at.wada811.utils.DumpUtils.java
public static String toString(Bundle bundle) { if (bundle == null) { return "null"; }/* w w w . j ava2 s . co m*/ JSONObject json = new JSONObject(); for (String key : bundle.keySet()) { try { Object value = bundle.get(key); json.put(key, DumpUtils.toString(value)); } catch (JSONException e) { e.printStackTrace(); } } return json.toString(); }
From source file:com.onesignal.NotificationBundleProcessor.java
public static JSONObject bundleAsJSONObject(Bundle bundle) { JSONObject json = new JSONObject(); Set<String> keys = bundle.keySet(); for (String key : keys) { try {/*from ww w. jav a 2 s. c om*/ json.put(key, bundle.get(key)); } catch (JSONException e) { } } return json; }
From source file:com.kakao.http.HttpRequestTask.java
/** * String/Boolean/Number ?./*from w ww . j a v a 2 s . c o m*/ */ public static void addQueryParams(BoundRequestBuilder requestBuilder, Bundle parameters) { if (parameters == null) return; Set<String> keys = parameters.keySet(); for (String key : keys) { Object value = parameters.get(key); String valueStr = null; if (value == null) { value = ""; } if (isSupportedParameterType(value)) { valueStr = parameterToString(value); } else { throw new IllegalArgumentException(String.format("Unsupported parameter type for GET request: %s", value.getClass().getSimpleName())); } requestBuilder.addQueryParameter(key, valueStr); } }
From source file:com.evollu.react.fcm.BundleJSONConverter.java
public static JSONObject convertToJSON(Bundle bundle) throws JSONException { JSONObject json = new JSONObject(); for (String key : bundle.keySet()) { Object value = bundle.get(key); if (value == null) { // Null is not supported. continue; }/*from w w w . j av a2s . c o m*/ // Special case List<String> as getClass would not work, since List is an interface if (value instanceof List<?>) { JSONArray jsonArray = new JSONArray(); @SuppressWarnings("unchecked") List<String> listValue = (List<String>) value; for (String stringValue : listValue) { jsonArray.put(stringValue); } json.put(key, jsonArray); continue; } // Special case Bundle as it's one way, on the return it will be JSONObject if (value instanceof Bundle) { json.put(key, convertToJSON((Bundle) value)); continue; } Setter setter = SETTERS.get(value.getClass()); if (setter == null) { throw new IllegalArgumentException("Unsupported type: " + value.getClass()); } setter.setOnJSON(json, key, value); } return json; }
From source file:com.kakao.http.HttpRequestTask.java
/** * String/Boolean/Number ? value ? ?? Map/Set ?. *//*from w w w .j a v a 2 s . co m*/ public static void addParams(final BoundRequestBuilder requestBuilder, final Bundle parameters) { if (parameters == null) return; Set<String> keys = parameters.keySet(); for (String key : keys) { Object value = parameters.get(key); String valueStr = null; if (value == null) { value = ""; } if (isSupportedParameterType(value)) { valueStr = parameterToString(value); } else if (value instanceof Map || value instanceof Set) { try { valueStr = objectMapper.writeValueAsString(value); } catch (JsonProcessingException e) { throw new IllegalArgumentException( String.format("Unsupported parameter type : %s", value.getClass().getSimpleName())); } } else { throw new IllegalArgumentException( String.format("Unsupported parameter type : %s", value.getClass().getSimpleName())); } requestBuilder.addParameter(key, valueStr); } }