List of usage examples for android.os Bundle keySet
public Set<String> keySet()
From source file:com.amazon.cordova.plugin.PushPlugin.java
private static JSONObject convertBundleToJson(Bundle extras) { if (extras == null) { return null; }//from ww w. j a va 2 s .co m try { JSONObject json; json = new JSONObject().put(EVENT, MESSAGE); JSONObject jsondata = new JSONObject(); Iterator<String> it = extras.keySet().iterator(); while (it.hasNext()) { String key = it.next(); Object value = extras.get(key); // System data from Android if (key.equals(FOREGROUND)) { json.put(key, extras.getBoolean(FOREGROUND)); } else if (key.equals(COLDSTART)) { json.put(key, extras.getBoolean(COLDSTART)); } else { // we encourage put the message content into message value // when server send out notification if (key.equals(MESSAGE)) { json.put(key, value); } if (value instanceof String) { // Try to figure out if the value is another JSON object String strValue = (String) value; if (strValue.startsWith("{")) { try { JSONObject json2 = new JSONObject(strValue); jsondata.put(key, json2); } catch (Exception e) { jsondata.put(key, value); } // Try to figure out if the value is another JSON // array } else if (strValue.startsWith("[")) { try { JSONArray json2 = new JSONArray(strValue); jsondata.put(key, json2); } catch (Exception e) { jsondata.put(key, value); } } else { jsondata.put(key, value); } } } // while } json.put(PAYLOAD, jsondata); LOG.v(TAG, "extrasToJSON: " + json.toString()); return json; } catch (JSONException e) { LOG.e(TAG, "extrasToJSON: JSON exception"); } return null; }
From source file:com.groupme.sdk.util.HttpUtils.java
public static InputStream openStream(HttpClient client, String url, int method, String body, Bundle params, Bundle headers) throws HttpResponseException { HttpResponse response;// w ww. j av a 2s . c om InputStream in = null; Log.v("HttpUtils", "URL = " + url); try { switch (method) { case METHOD_GET: url = url + "?" + encodeParams(params); HttpGet get = new HttpGet(url); if (headers != null && !headers.isEmpty()) { for (String header : headers.keySet()) { get.setHeader(header, headers.getString(header)); } } response = client.execute(get); break; case METHOD_POST: if (body != null) { url = url + "?" + encodeParams(params); } HttpPost post = new HttpPost(url); Log.d(Constants.LOG_TAG, "URL: " + url); if (headers != null && !headers.isEmpty()) { for (String header : headers.keySet()) { post.setHeader(header, headers.getString(header)); } } if (body == null) { List<NameValuePair> pairs = bundleToList(params); post.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8)); } else { post.setEntity(new StringEntity(body)); } response = client.execute(post); break; case METHOD_PUT: if (body != null) { url = url + "?" + encodeParams(params); } HttpPut put = new HttpPut(url); if (headers != null && !headers.isEmpty()) { for (String header : headers.keySet()) { put.setHeader(header, headers.getString(header)); } } if (body == null) { List<NameValuePair> pairs = bundleToList(params); put.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8)); } else { put.setEntity(new StringEntity(body)); } response = client.execute(put); break; default: throw new UnsupportedOperationException("Cannot execute HTTP method: " + method); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode > 400) { throw new HttpResponseException(statusCode, read(response.getEntity().getContent())); } in = response.getEntity().getContent(); } catch (ClientProtocolException e) { Log.e(Constants.LOG_TAG, "Client error: " + e.toString()); } catch (IOException e) { Log.e(Constants.LOG_TAG, "IO error: " + e.toString()); } return in; }
From source file:com.facebook.InsightsLogger.java
private static String buildJSONForEvent(String eventName, double valueToSum, Bundle parameters) { String result;/* w w w. j a va 2 s.c o m*/ try { // Build custom event payload JSONObject eventObject = new JSONObject(); eventObject.put("_eventName", eventName); if (valueToSum != 1.0) { eventObject.put("_valueToSum", valueToSum); } if (parameters != null) { Set<String> keys = parameters.keySet(); for (String key : keys) { Object value = parameters.get(key); if (!(value instanceof String) && !(value instanceof Number)) { notifyDeveloperError( String.format("Parameter '%s' must be a string or a numeric type.", key)); } eventObject.put(key, value); } } JSONArray eventArray = new JSONArray(); eventArray.put(eventObject); result = eventArray.toString(); } catch (JSONException exception) { notifyDeveloperError(exception.toString()); result = null; } return result; }
From source file:com.zrlh.llkc.funciton.Http_Utility.java
/** * Construct a url encoded entity by parameters . * // ww w .j av a 2 s . c o m * @param bundle * :parameters key pairs * @return UrlEncodedFormEntity: encoed entity */ public static UrlEncodedFormEntity getPostParamters(Bundle bundle) throws Exception { if (bundle == null || bundle.isEmpty()) { return null; } try { List<NameValuePair> form = new ArrayList<NameValuePair>(); for (String key : bundle.keySet()) { form.add(new BasicNameValuePair(key, bundle.getString(key))); } UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, "UTF-8"); return entity; } catch (UnsupportedEncodingException e) { throw new UnsupportedEncodingException(); } }
From source file:com.sonyericsson.android.drm.drmlicenseservice.DLSHttpClient.java
private static void addParameters(Bundle parameters, HttpRequestBase request) { if (parameters != null && request != null) { Bundle headers = parameters.getBundle(Constants.DRM_KEYPARAM_HTTP_HEADERS); if (headers != null && headers.size() > 0) { for (String headerKey : headers.keySet()) { if (headerKey != null && headerKey.length() > 0) { String headerValue = headers.getString(headerKey); if (headerValue != null && headerValue.length() > 0) { request.setHeader(headerKey, headerValue); }//from w ww .j a v a 2 s.c o m } } } } }
From source file:com.renren.api.connect.android.Util.java
/** * Key-value??&?URL??//from w ww. j a v a 2 s.c o m * * @param parameters * @return */ public static String encodeUrl(Bundle parameters) { if (parameters == null) { return ""; } StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { if (first) { first = false; } else { sb.append("&"); } sb.append(key + "=" + URLEncoder.encode(parameters.getString(key))); //sb.append(key + "=" + parameters.getString(key)); } return sb.toString(); }
From source file:com.ztspeech.weibo.sdk.renren.Util.java
/** * Key-value??&?URL??/*from www . ja v a 2 s .c o m*/ * * @param parameters * @return */ public static String encodeUrl(Bundle parameters) { if (parameters == null) { return ""; } StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { if (first) { first = false; } else { sb.append("&"); } sb.append(key + "=" + URLEncoder.encode(parameters.getString(key))); // sb.append(key + "=" + parameters.getString(key)); } return sb.toString(); }
From source file:com.iStudy.Study.Renren.Util.java
/** * Key-value??&?URL??//from w w w.j a v a 2 s . c o m * * @param parameters * @return */ @SuppressWarnings("deprecation") public static String encodeUrl(Bundle parameters) { if (parameters == null) { return ""; } StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { if (first) { first = false; } else { sb.append("&"); } sb.append(key + "=" + URLEncoder.encode(parameters.getString(key))); //sb.append(key + "=" + parameters.getString(key)); } return sb.toString(); }
From source file:com.cloudzilla.fb.FacebookServiceProxy.java
private static String toString(Bundle bundle) { StringBuilder sb = new StringBuilder(); sb.append("{"); for (String key : bundle.keySet()) { sb.append(key + ":" + bundle.get(key) + ","); }/*w w w. ja v a 2 s . c o m*/ sb.append("}"); return sb.toString(); }
From source file:com.commontime.plugin.notification.Notification.java
private static JSONObject convertBundleToJson(Bundle extras) { try {/*from w w w. j a va 2 s . c o m*/ JSONObject json; json = new JSONObject().put("event", "message"); Iterator<String> it = extras.keySet().iterator(); while (it.hasNext()) { String key = it.next(); Object value = extras.get(key); // System data from Android if (key.equals("from") || key.equals("collapse_key")) { json.put(key, value); } else if (key.equals("foreground")) { json.put(key, extras.getBoolean("foreground")); } else if (key.equals("coldstart")) { json.put(key, extras.getBoolean("coldstart")); } else if (key.equals("title")) { json.put(key, extras.getString("title")); } else if (key.equals("message")) { json.put(key, extras.getString("message")); } else if (key.equals("payload")) { createPayloadObject(json, (String) value); } else { if (value instanceof String) { createPayloadObject(json, (String) value); } } } // while json.put("service", "GCM"); return json; } catch (JSONException e) { } return null; }