List of usage examples for android.os Bundle keySet
public Set<String> keySet()
From source file:Main.java
public static JSONObject toJsonObject(Bundle bundle) { JSONObject jsonObject = new JSONObject(); try {//from w w w . j a v a2s . co m for (String key : bundle.keySet()) { Object elm = bundle.get(key); if (elm instanceof Bundle) { jsonObject.put(key, toJsonObject((Bundle) elm)); } else if (elm instanceof List<?>) { jsonObject.put(key, toJsonArray((List<?>) elm)); } else if (elm instanceof Array) { jsonObject.put(key, toJsonArray((Array) elm)); } else { jsonObject.put(key, elm.toString()); } } } catch (JSONException e) { Log.d("Helper.toJsonObject", "Exception"); e.printStackTrace(); } return jsonObject; }
From source file:Main.java
public static String encodePostBody(Bundle parameters, String boundary) { if (parameters == null) return ""; StringBuilder sb = new StringBuilder(); for (String key : parameters.keySet()) { // if (parameters.getByteArray(key) != null) { // continue; // } sb.append("Content-Disposition: form-data; name=\"" + key + "\"\r\n\r\n" + parameters.getString(key)); sb.append("\r\n" + "--" + boundary + "\r\n"); }/* w ww.j a v a2s . c o m*/ return sb.toString(); }
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 www.jav a 2 s .com*/ return true; }
From source file:Main.java
public static void dumpBundleKeys(Bundle bundle) { if (bundle == null) { Log.d(TAG, "extras bundle is null"); return;/*from w ww. j ava 2 s .com*/ } Log.d(TAG, "bundle keys:"); for (String o : bundle.keySet()) { Log.d(TAG, o); } }
From source file:de.ncoder.sensorsystem.android.logging.JSONUtils.java
private static Object wrapBundle(Bundle b) { try {/*from w w w. j a v a 2s . c o m*/ JSONObject json = new JSONObject(); for (String key : b.keySet()) { json.put(key, wrap(b.get(key))); } return json; } catch (JSONException e) { return b.toString() + " threw " + e.toString(); } }
From source file:Main.java
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;/*from w w w . j ava 2 s . c om*/ else sb.append("&"); sb.append(key + "=" + parameters.getString(key)); } return sb.toString(); }
From source file:Main.java
public static Map<String, Serializable> bundleToMap(Bundle bundle) { Map<String, Serializable> result = new HashMap<String, Serializable>(); if (bundle == null) return result; for (String key : bundle.keySet()) { result.put(key, bundle.getSerializable(key)); }// w w w .j a v a 2s . c o m return result; }
From source file:Main.java
/** * Generate the multi-part post body providing the parameters and boundary * string/*from ww w. j av a2 s. c o m*/ * * @param parameters the parameters need to be posted * @param boundary the random string as boundary * @return a string of the post body */ public static String encodePostBody(Bundle parameters, String boundary) { if (parameters == null) return ""; StringBuilder sb = new StringBuilder(); for (String key : parameters.keySet()) { Object parameter = parameters.get(key); if (!(parameter instanceof String)) { continue; } sb.append("Content-Disposition: form-data; name=\"" + key + "\"\r\n\r\n" + (String) parameter); sb.append("\r\n" + "--" + boundary + "\r\n"); } return sb.toString(); }
From source file:Main.java
public static String encodeUrl(Bundle parameters) { if (parameters == null) { return ""; }/*from w ww .j a v a2 s .co m*/ StringBuilder sb = new StringBuilder(); boolean first = true; for (String key : parameters.keySet()) { if (first) first = false; else sb.append("&"); sb.append(URLEncoder.encode(key) + "=" + URLEncoder.encode(parameters.getString(key))); } return sb.toString(); }
From source file:Main.java
/** * Generate the multi-part post body providing the parameters and boundary * string/*from w w w. ja v a 2 s . c o m*/ * * @param parameters the parameters need to be posted * @param boundary the random string as boundary * @return a string of the post body */ @Deprecated public static String encodePostBody(Bundle parameters, String boundary) { if (parameters == null) return ""; StringBuilder sb = new StringBuilder(); for (String key : parameters.keySet()) { Object parameter = parameters.get(key); if (!(parameter instanceof String)) { continue; } sb.append("Content-Disposition: form-data; name=\"" + key + "\"\r\n\r\n" + (String) parameter); sb.append("\r\n" + "--" + boundary + "\r\n"); } return sb.toString(); }