Example usage for android.os Bundle keySet

List of usage examples for android.os Bundle keySet

Introduction

In this page you can find the example usage for android.os Bundle keySet.

Prototype

public Set<String> keySet() 

Source Link

Document

Returns a Set containing the Strings used as keys in this Bundle.

Usage

From source file:org.jboss.aerogear.cordova.push.PushPlugin.java

/**
 * Serializes a bundle to JSON.//from w  w  w .ja  v  a2  s .  c om
 * @param message to be serialized
 */
private static JSONObject convertBundleToJson(Bundle message) {
    try {
        JSONObject json;
        json = new JSONObject();

        JSONObject jsondata = new JSONObject();
        for (String key : message.keySet()) {
            Object value = message.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, message.getBoolean("foreground"));
            } else if (key.equals("coldstart")) {
                json.put(key, message.getBoolean("coldstart"));
            } else {
                // Maintain backwards compatibility
                if (key.equals("message") || key.equals("msgcnt") || key.equals("sound")
                        || key.equals("alert")) {
                    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:count.ly.messaging.TitaniumCountlyAndroidMessagingModule.java

private static String printBundle(Bundle bundle) {
    StringBuilder sb = new StringBuilder();
    for (String key : bundle.keySet()) {
        sb.append("\nkey:" + key + ", value:" + bundle.getString(key));
    }/*  w  w  w.ja va2s  .c o m*/
    return sb.toString();
}

From source file:cn.bidaround.ytcore.kaixin.KaixinUtil.java

/**
 * ?multi-part??/* w  ww.ja  v a2  s  .com*/
 * 
 * @param parameters
 *            key-value??
 * @param boundary
 *            ?
 * @return multi-part??
 */
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");
    }

    return sb.toString();
}

From source file:count.ly.messaging.TitaniumCountlyAndroidMessagingModule.java

private static HashMap<String, String> bundleToHashMap(Bundle bundle) {
    HashMap<String, String> hash = new HashMap<String, String>();
    Set<String> keys = bundle.keySet();
    for (String key : keys) {
        hash.put(key, bundle.get(key).toString());
    }//from  w  w  w.  j a  va 2  s.  c  o  m
    return hash;
}

From source file:com.ds.kaixin.Util.java

/**
 * key-value&URL/*  ww w .j  a  va 2s .  co  m*/
 * 
 * @param parameters
 *            key-value
 * @return &URL
 */
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(URLEncoder.encode(key) + "=" + URLEncoder.encode(parameters.getString(key)));
    }
    return sb.toString();
}

From source file:cn.bidaround.ytcore.kaixin.KaixinUtil.java

/**
 * key-value????&?URL??//from   w w w  . j  a v  a 2  s  .  c o  m
 * 
 * @param parameters
 *            key-value??
 * @return &?URL?
 */
@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("&");
        if (parameters.getString(key) != null) {
            sb.append(URLEncoder.encode(key) + "=" + URLEncoder.encode(parameters.getString(key)));
        }
    }
    return sb.toString();
}

From source file:se.frostyelk.cordova.parse.plugin.ParsePlugin.java

private static JSONObject convertBundleToJson(Bundle extras) {
    try {/*  www.jav  a 2  s . c  o  m*/
        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("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 {
                // Maintain backwards compatibility
                if (key.equals("message") || key.equals("msgcnt") || key.equals("soundname")) {
                    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.i(LOGTAG, "extrasToJSON: " + json.toString());

        return json;
    } catch (JSONException e) {
        Log.e(LOGTAG, "extrasToJSON: JSON exception");
    }
    return null;
}

From source file:com.hybris.mobile.data.WebServiceDataProvider.java

public static String encodePostBody(Bundle parameters) {
    if (parameters == null) {
        return "";
    }//w w  w  .  ja v a  2 s .  co  m

    StringBuilder sb = new StringBuilder();

    for (Iterator<String> i = parameters.keySet().iterator(); i.hasNext();) {
        String key = i.next();
        Object parameter = parameters.get(key);
        if (!(parameter instanceof String)) {
            continue;
        }

        try {
            sb.append(URLEncoder.encode(key, "UTF-8"));
            sb.append("=");
            sb.append(URLEncoder.encode((String) parameter, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // TODO report parse error
            LoggingUtils.e(LOG_TAG, "Error encoding \"" + key + "\" or \"" + parameter + "\" to UTF-8 ."
                    + e.getLocalizedMessage(), null);
        }

        if (i.hasNext()) {
            sb.append("&");
        }
    }
    return sb.toString();
}

From source file:com.gcm.client.GcmHelper.java

/**
 * A debugging method which helps print the entire bundle
 *
 * @param data instance of the {@link Bundle} which needs to be printed
 *//*from  ww w  .  ja  va 2  s.  co  m*/
static void printBundle(Bundle data) {
    try {
        if (null == data) {
            Log.d(TAG, "printBundle:No extras to log");
            return;
        }
        Set<String> ketSet = data.keySet();
        if (null == ketSet || ketSet.isEmpty())
            return;
        Log.d(TAG, "------Start of bundle extras------");
        for (String key : ketSet) {
            Object obj = data.get(key);
            if (null != obj) {
                Log.d(TAG, "[ " + key + " = " + obj.toString() + " ]");
            }
        }
        Log.d(TAG, "-------End of bundle extras-------");
    } catch (Exception e) {
        if (DEBUG_ENABLED)
            Log.e(TAG, "printBundle", e);
    }
}

From source file:net.neoturbine.autolycus.internal.BusTimeAPI.java

/**
 * Requests the XML data for a given action and parameters. Matches the
 * <code>system</code> input with a hard-coded internal list to know which
 * server to use. Note that this MUST not be run in the UI thread.
 * //ww w .jav  a2  s . c om
 * @param context
 *            Currently unused, but needed for analytics.
 * @param verb
 *            The string in the last part of the Base URL within the API
 *            documentation.
 * @param system
 *            One of the internally supported transit systems.
 * @param params
 *            a Bundle containing the parameters to be passed within its
 *            extras.
 * @return an XmlPullParser with the XML tree resulting from this API call.
 * 
 * @throws ClientProtocolException
 * @throws IOException
 * @throws XmlPullParserException
 */
private static XmlPullParser loadData(Context context, String verb, String system, Bundle params)
        throws ClientProtocolException, IOException, XmlPullParserException {
    ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>();
    if (params != null) {
        for (String name : params.keySet()) {
            qparams.add(new BasicNameValuePair(name, params.getString(name)));
        }
    }

    String server = "";
    String key = "";
    if (system.equals("Chicago Transit Authority")) {
        server = "www.ctabustracker.com";
        key = "HeDbySM4CUDgRDsrGnRGZmD6K";
    } else if (system.equals("Ohio State University TRIP")) {
        server = "trip.osu.edu";
        key = "auixft7SWR3pWAcgkQfnfJpXt";
    } else if (system.equals("MTA New York City Transit")) {
        server = "bustime34.mta.info";
        key = "t7YxRNCmvVCfrZzrcMFeYegjp";
    }

    qparams.add(new BasicNameValuePair("key", key));

    // assemble the url
    URI uri;
    try {
        uri = URIUtils.createURI("http", // Protocol
                server, // server
                80, // specified in API documentation
                "/bustime/api/v1/" + verb, // path
                URLEncodedUtils.format(qparams, "UTF-8"), null);
    } catch (URISyntaxException e) {
        // shouldn't happen
        throw new RuntimeException(e);
    }

    // assemble our request
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(uri);
    Log.i(TAG, "Retrieving " + httpget.getURI().toString());
    // from localytics recordEvent(context,system,verb,false);

    // ah, the blocking
    HttpResponse response = httpClient.execute(httpget);

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        throw new RuntimeException(response.getStatusLine().toString());
    }
    InputStream content = response.getEntity().getContent();
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    XmlPullParser xpp = factory.newPullParser();
    xpp.setInput(content, null);
    return xpp;
}