Example usage for android.os Bundle get

List of usage examples for android.os Bundle get

Introduction

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

Prototype

@Nullable
public Object get(String key) 

Source Link

Document

Returns the entry with the given key as an object.

Usage

From source file:Main.java

public static JSONObject toJsonObject(Bundle bundle) {
    JSONObject jsonObject = new JSONObject();
    try {/*from   w w w  .ja  va  2s .  c om*/
        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:de.ncoder.sensorsystem.android.logging.JSONUtils.java

private static Object wrapBundle(Bundle b) {
    try {/*from  w w  w. ja va  2s.c  om*/
        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

/**
 * Generate the multi-part post body providing the parameters and boundary
 * string//from  w  w w .  j  a 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
 */
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

/**
 * Generate the multi-part post body providing the parameters and boundary
 * string//from  w  w w. j  av  a2s. co 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();
}

From source file:com.mikecorrigan.bohrium.pubsub.JSONCodec.java

public static JSONObject toJson(final Bundle bundle) {
    Log.v(TAG, "toJson");

    JSONObject j = new JSONObject();
    try {/*from  w w w .j  ava 2 s .com*/
        for (final String key : bundle.keySet()) {
            final Object value = bundle.get(key);
            Log.v(TAG, "key=" + key + ", value=" + value.toString());
            j.put(key, value.toString());
        }

        return j;
    } catch (JSONException e) {
        Log.e(TAG, "exception=" + e);
        Log.e(TAG, Log.getStackTraceString(e));
    }

    return null;
}

From source file:Main.java

public static void printeBackup(Bundle data, String lev) {
    if (!debug) {
        return;//  ww  w.  j a v a2  s .c o m
    }
    Log.d("backup", "---- " + lev + " begin ----");
    if (null != data) {
        for (String key : data.keySet()) {
            Object value = data.get(key);
            Log.d("backup", "key = " + key + " , value = " + value);
        }
    }
}

From source file:Main.java

public static Uri buildUri(String authority, String path, Bundle parameters) {
    Uri.Builder builder = new Uri.Builder();
    builder.scheme(URL_SCHEME);// www . j  a v  a2s  . com
    builder.authority(authority);
    builder.path(path);
    for (String key : parameters.keySet()) {
        Object parameter = parameters.get(key);
        if (parameter instanceof String) {
            builder.appendQueryParameter(key, (String) parameter);
        }
    }
    return builder.build();
}

From source file:Main.java

public static String encodeUrl(Bundle parameters) {
    if (parameters == null) {
        return "";
    }/*from ww  w .j a  va2s . c o m*/

    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (String key : parameters.keySet()) {
        Object parameter = parameters.get(key);
        if (!(parameter instanceof String)) {
            continue;
        }

        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

@Deprecated
public static String encodeUrl(Bundle parameters) {
    if (parameters == null) {
        return "";
    }//w  ww .  j  a  v a2  s . co m

    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (String key : parameters.keySet()) {
        Object parameter = parameters.get(key);
        if (!(parameter instanceof String)) {
            continue;
        }

        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

public static void appendBundleAsUrlArgs(StringBuilder builder, Bundle properties) {
    if (builder == null) {
        return;/*  w  w w .  j  a v a 2 s  .  c  om*/
    }
    Object[] keySetIds = properties.keySet().toArray();
    for (int i = 0; i < keySetIds.length; i++) {
        String key = (String) keySetIds[i];
        if (properties.get(key) == null) {
            continue;
        }
        appendPropertyAsUrlArgs(builder, key, properties.get(key).toString());
        if (i < keySetIds.length - 1)
            builder.append(URL_AND);
    }
}