Example usage for android.os Bundle getString

List of usage examples for android.os Bundle getString

Introduction

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

Prototype

@Nullable
public String getString(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.facebook.share.ShareApi.java

private static void handleImagesOnAction(Bundle parameters) {
    // In general, graph objects are passed by reference (ID/URL). But if this is an OG Action,
    // we need to pass the entire values of the contents of the 'image' property, as they
    // contain important metadata beyond just a URL.
    String imageStr = parameters.getString("image");
    if (imageStr != null) {
        try {// w w  w  .j ava2s.c  om
            // Check to see if this is an json array. Will throw if not
            JSONArray images = new JSONArray(imageStr);
            for (int i = 0; i < images.length(); ++i) {
                JSONObject jsonImage = images.optJSONObject(i);
                if (jsonImage != null) {
                    putImageInBundleWithArrayFormat(parameters, i, jsonImage);
                } else {
                    // If we don't have jsonImage we probably just have a url
                    String url = images.getString(i);
                    parameters.putString(String.format(Locale.ROOT, "image[%d][url]", i), url);
                }
            }
            parameters.remove("image");
            return;
        } catch (JSONException ex) {
            // We couldn't parse the string as an array
        }

        // If the image is not in an array it might just be an single photo
        try {
            JSONObject image = new JSONObject(imageStr);
            putImageInBundleWithArrayFormat(parameters, 0, image);
            parameters.remove("image");
        } catch (JSONException exception) {
            // The image was not in array format or a json object and can be safely passed
            // without modification
        }
    }
}

From source file:com.miloisbadboy.net.Utility.java

/**
 * Construct a url encoded entity by parameters .
 * /*  w w  w.ja va  2s.  c  o m*/
 * @param bundle
 *            :parameters key pairs
 * @return UrlEncodedFormEntity: encoed entity
 */
public static UrlEncodedFormEntity getPostParamters(Bundle bundle) throws RequestException {
    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 RequestException(e);
    }
}

From source file:com.facebook.share.internal.ShareInternalUtility.java

/**
 * Returns the id of the published post. This is only returned if the user has previously
 * given the app publish permissions./* w w  w .jav a2s. c  o  m*/
 *
 * @param result the bundle passed back to onActivityResult
 * @return the id of the published post
 */
public static String getShareDialogPostId(Bundle result) {
    if (result.containsKey(ShareConstants.RESULT_POST_ID)) {
        return result.getString(ShareConstants.RESULT_POST_ID);
    }
    if (result.containsKey(ShareConstants.EXTRA_RESULT_POST_ID)) {
        return result.getString(ShareConstants.EXTRA_RESULT_POST_ID);
    }
    return result.getString(ShareConstants.WEB_DIALOG_RESULT_PARAM_POST_ID);
}

From source file:com.renren.api.connect.android.Util.java

/**
 * Key-value??&?URL??//from   w  w  w . j  av  a2 s.co 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??//www  .j a va  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??/* w  ww.  ja  v  a 2s.  co 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.facebook.android.FBUtil.java

/**
 * Connect to an HTTP URL and return the response as a string.
 *
 * Note that the HTTP method override is used on non-GET requests. (i.e.
 * requests are made as "POST" with method specified in the body).
 *
 * @param url - the resource to open: must be a welformed URL
 * @param method - the HTTP method to use ("GET", "POST", etc.)
 * @param params - the query parameter for the URL (e.g. access_token=foo)
 * @return the URL contents as a String/*  w w w.j av a  2  s .c  om*/
 * @throws MalformedURLException - if the URL format is invalid
 * @throws IOException - if a network problem occurs
 */
public static String openUrl(String url, String method, Bundle params)
        throws MalformedURLException, IOException {
    // random string as boundary for multi-part http post
    String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f";
    String endLine = "\r\n";

    OutputStream os;

    // Try to get filename key
    String filename = params.getString("filename");

    // If found
    if (filename != null) {
        // Remove from params
        params.remove("filename");
    }

    if (method.equals("GET")) {
        url = url + "?" + encodeUrl(params);
    }
    Log.d("Facebook-FBUtil", method + " URL: " + url);
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestProperty("User-Agent",
            System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK");
    if (!method.equals("GET")) {
        Bundle dataparams = new Bundle();
        for (String key : params.keySet()) {
            if (params.getByteArray(key) != null) {
                dataparams.putByteArray(key, params.getByteArray(key));
            }
        }

        // use method override
        if (!params.containsKey("method")) {
            params.putString("method", method);
        }

        if (params.containsKey("access_token")) {
            String decoded_token = URLDecoder.decode(params.getString("access_token"));
            params.putString("access_token", decoded_token);
        }

        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary);
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.connect();
        os = new BufferedOutputStream(conn.getOutputStream());

        os.write(("--" + strBoundary + endLine).getBytes());
        os.write((encodePostBody(params, strBoundary)).getBytes());
        os.write((endLine + "--" + strBoundary + endLine).getBytes());

        if (!dataparams.isEmpty()) {

            for (String key : dataparams.keySet()) {
                os.write(("Content-Disposition: form-data; filename=\"" + ((filename) != null ? filename : key)
                        + "\"" + endLine).getBytes());
                os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes());
                os.write(dataparams.getByteArray(key));
                os.write((endLine + "--" + strBoundary + endLine).getBytes());

            }
        }
        os.flush();
    }

    String response = "";
    try {
        response = read(conn.getInputStream());
    } catch (FileNotFoundException e) {
        // Error Stream contains JSON that we can parse to a FB error
        response = read(conn.getErrorStream());
    }
    return response;
}

From source file:com.facebook.share.internal.ShareInternalUtility.java

/**
 * Returns the gesture with which the user completed the native dialog. This is only returned
 * if the user has previously authorized the calling app with basic permissions.
 *
 * @param result the bundle passed back to onActivityResult
 * @return "post" or "cancel" as the completion gesture
 *//*  ww w.  j av a  2 s .  c o m*/
public static String getNativeDialogCompletionGesture(Bundle result) {
    if (result.containsKey(NativeProtocol.RESULT_ARGS_DIALOG_COMPLETION_GESTURE_KEY)) {
        return result.getString(NativeProtocol.RESULT_ARGS_DIALOG_COMPLETION_GESTURE_KEY);
    }
    return result.getString(NativeProtocol.EXTRA_DIALOG_COMPLETION_GESTURE_KEY);
}

From source file:Main.java

public static void registerNewSourceSinkConnection(int counter, Bundle bundle) {
    Log.i("PEP", "in registerNewSourceSinkConnection(int counter, Bundle bundle)");
    int taintInfoKeyCounter = 0;

    if (bundle != null) {
        for (String intentKey : bundle.keySet()) {
            if (intentKey.startsWith(keyBaseName)) {
                String possibleNumber = intentKey.substring(keyBaseName.length());
                if (possibleNumber.length() > 0 && TextUtils.isDigitsOnly(possibleNumber)) {
                    int currentCounter = Integer.parseInt(possibleNumber);
                    if (taintInfoKeyCounter < currentCounter)
                        taintInfoKeyCounter = currentCounter;
                }//from w w  w.  j a va2s  .  co m
            }
        }

        if (taintInfoKeyCounter == 0) {
            Log.i("PEP", "bundle:" + bundle.toString());
            if (bundle.containsKey(keyBaseName)) {
                String taintSourceCats = bundle.getString(keyBaseName);
                String[] allCats = taintSourceCats.split(",");
                sourceSinkConnection.put(counter, new HashSet<String>(Arrays.asList(allCats)));
            }
        } else {
            if (bundle.containsKey(keyBaseName + taintInfoKeyCounter)) {
                String taintSourceCats = bundle.getString(keyBaseName + taintInfoKeyCounter);
                String[] allCats = taintSourceCats.split(",");
                sourceSinkConnection.put(counter, new HashSet<String>(Arrays.asList(allCats)));
            }
        }
    }
}

From source file:com.dongfang.dicos.sina.UtilSina.java

/**
 * Construct a url encoded entity by parameters .
 * /*from w  w  w .ja  va2s .c  om*/
 * @param bundle
 *            :parameters key pairs
 * @return UrlEncodedFormEntity: encoed entity
 */
public static UrlEncodedFormEntity getPostParamters(Bundle bundle) throws WeiboException {
    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 WeiboException(e);
    }
}