Example usage for android.os Bundle remove

List of usage examples for android.os Bundle remove

Introduction

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

Prototype

public void remove(String key) 

Source Link

Document

Removes any entry with the given key from the mapping of this Bundle.

Usage

From source file:Main.java

/**
 * Removes object from the bundle.//from  www .java2 s  .com
 *
 * @param clazz  of object
 * @param bundle to get from
 * @param <T>    type of object
 */
public static <T> void removeFromBundle(Class<T> clazz, Bundle bundle) {
    if (bundle != null) {
        bundle.remove(clazz.getSimpleName());
    }
}

From source file:Main.java

/**
 * Removes key if value is null/*from   w  ww  .  ja  va 2 s  . c om*/
 */
@NonNull
public static Bundle toBundle(Bundle bundleIn, String key, Long value) {
    Bundle bundle = bundleIn == null ? new Bundle() : bundleIn;
    if (!TextUtils.isEmpty(key)) {
        if (value == null) {
            bundle.remove(key);
        } else {
            bundle.putLong(key, value);
        }
    }
    return bundle;
}

From source file:Main.java

public static void setSlotReservationFlags(Bundle extras, boolean reservePlayingQueueSlot,
        boolean reserveSkipToNextSlot, boolean reserveSkipToPrevSlot) {
    if (reservePlayingQueueSlot)
        extras.putBoolean(SLOT_RESERVATION_QUEUE, true);
    else//w  w w.  j  a  v a2 s .com
        extras.remove(SLOT_RESERVATION_QUEUE);
    if (reserveSkipToPrevSlot)
        extras.putBoolean(SLOT_RESERVATION_SKIP_TO_PREV, true);
    else
        extras.remove(SLOT_RESERVATION_SKIP_TO_PREV);
    if (reserveSkipToNextSlot)
        extras.putBoolean(SLOT_RESERVATION_SKIP_TO_NEXT, true);
    else
        extras.remove(SLOT_RESERVATION_SKIP_TO_NEXT);
}

From source file:Main.java

public static void setSlotReservationFlags(Bundle extras, boolean reservePlayingQueueSlot,
        boolean reserveSkipToNextSlot, boolean reserveSkipToPrevSlot) {
    if (reservePlayingQueueSlot) {
        extras.putBoolean(SLOT_RESERVATION_QUEUE, true);
    } else {//from  w w w.j  a v  a  2  s  .c  o m
        extras.remove(SLOT_RESERVATION_QUEUE);
    }
    if (reserveSkipToPrevSlot) {
        extras.putBoolean(SLOT_RESERVATION_SKIP_TO_PREV, true);
    } else {
        extras.remove(SLOT_RESERVATION_SKIP_TO_PREV);
    }
    if (reserveSkipToNextSlot) {
        extras.putBoolean(SLOT_RESERVATION_SKIP_TO_NEXT, true);
    } else {
        extras.remove(SLOT_RESERVATION_SKIP_TO_NEXT);
    }
}

From source file:org.linkdroid.WebhookPostService.java

public static Bundle newPostDataBundle(Intent originator) {
    Bundle bundle = new Bundle();
    if (originator.getExtras() != null) {
        bundle.putAll(originator.getExtras());
    }//from w w w  .  j  av a 2 s.  co m
    // Sanitize the linkdroid extras from data bundle in case originating
    // intent extras set them. We do this for all linkdroid Extras except
    // for the SMS extras.
    bundle.remove(Extras.INTENT_ACTION);
    bundle.remove(Extras.INTENT_TYPE);
    bundle.remove(Extras.INTENT_CATEGORIES);
    bundle.remove(Extras.HMAC);
    bundle.remove(Extras.NONCE);
    bundle.remove(Extras.STREAM);
    bundle.remove(Extras.STREAM_HMAC);
    bundle.remove(Extras.STREAM_MIME_TYPE);
    bundle.remove(Extras.USER_INPUT);
    if (originator.getAction() != null) {
        bundle.putString(Extras.INTENT_ACTION, originator.getAction());
    }
    if (originator.getType() != null) {
        bundle.putString(Extras.INTENT_TYPE, originator.getType());
    }
    if (originator.getCategories() != null) {
        bundle.putString(Extras.INTENT_CATEGORIES, StringUtils.join(originator.getCategories(), " "));
    }

    return bundle;
}

From source file:com.onesignal.NotificationBundleProcessor.java

private static void prepareBundle(Bundle gcmBundle) {
    if (gcmBundle.containsKey("o")) {
        try {//from ww  w .  j a  va  2 s  .  c o m
            JSONObject customJSON = new JSONObject(gcmBundle.getString("custom"));
            JSONObject additionalDataJSON;

            if (customJSON.has("a"))
                additionalDataJSON = customJSON.getJSONObject("a");
            else
                additionalDataJSON = new JSONObject();

            JSONArray buttons = new JSONArray(gcmBundle.getString("o"));
            gcmBundle.remove("o");
            for (int i = 0; i < buttons.length(); i++) {
                JSONObject button = buttons.getJSONObject(i);

                String buttonText = button.getString("n");
                button.remove("n");
                String buttonId;
                if (button.has("i")) {
                    buttonId = button.getString("i");
                    button.remove("i");
                } else
                    buttonId = buttonText;

                button.put("id", buttonId);
                button.put("text", buttonText);

                if (button.has("p")) {
                    button.put("icon", button.getString("p"));
                    button.remove("p");
                }
            }

            additionalDataJSON.put("actionButtons", buttons);
            additionalDataJSON.put("actionSelected", DEFAULT_ACTION);
            if (!customJSON.has("a"))
                customJSON.put("a", additionalDataJSON);

            gcmBundle.putString("custom", customJSON.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.bpd.facebook.Util.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//from w  w  w .  j ava  2s . 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-Util", 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.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/*from   ww  w. java 2s . co  m*/
 * @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:pub.devrel.easygoogle.gcm.EasyMessageService.java

@Override
public void onHandleIntent(Intent intent) {
    String action = intent.getAction();
    if (getString(R.string.action_new_token).equals(action)) {
        String token = intent.getStringExtra(EXTRA_TOKEN);

        onNewToken(token);//w w  w .j a v a  2s  .  c om
    }

    if (getString(R.string.action_new_message).equals(action)) {
        String from = intent.getStringExtra(EXTRA_FROM);
        Bundle data = intent.getExtras();
        data.remove(EXTRA_FROM);

        onMessageReceived(from, data);
    }
}

From source file:org.mariotaku.twidere.fragment.support.AbsUsersFragment.java

@Override
public final Loader<Data> onCreateLoader(int id, Bundle args) {
    final boolean fromUser = args.getBoolean(EXTRA_FROM_USER);
    args.remove(EXTRA_FROM_USER);
    return onCreateUsersLoader(getActivity(), args, fromUser);
}