Example usage for android.os Bundle isEmpty

List of usage examples for android.os Bundle isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if the mapping of this Bundle is empty, false otherwise.

Usage

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/* www  .  ja v a2  s. c  o 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:com.data.pack.Util.java

/**
 * Connect to an HTTP URL and return the response as a string.
 * //from  w  ww .j  a va2  s. c om
 * 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
 * @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;

    if (method.equals("GET")) {
        url = url + "?" + encodeUrl(params);
    }
    Util.logd("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=\"" + 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:uk.co.ashtonbrsc.intentexplode.Explode.java

private void rememberIntent(Intent original) {
    this.originalIntent = getUri(original);

    Intent copy = cloneIntent(this.originalIntent);

    final Bundle originalExtras = original.getExtras();

    if (originalExtras != null) {
        // bugfix #14: collect extras that are lost in the intent <-> string conversion
        Bundle additionalExtrasBundle = new Bundle(originalExtras);
        for (String key : originalExtras.keySet()) {
            if (copy.hasExtra(key)) {
                additionalExtrasBundle.remove(key);
            }/* www  .  j  a v a  2  s .c o  m*/
        }

        if (!additionalExtrasBundle.isEmpty()) {
            additionalExtras = additionalExtrasBundle;
        }
    }

}

From source file:org.libreoffice.ui.LibreOfficeUIActivity.java

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onRestoreInstanceState(savedInstanceState);
    if (savedInstanceState.isEmpty()) {
        return;//from w w  w . ja  v a2  s  .co m
    }
    if (documentProvider == null) {
        Log.d(LOGTAG, "onRestoreInstanceState - documentProvider is null");
        documentProvider = DocumentProviderFactory.getInstance()
                .getProvider(savedInstanceState.getInt(DOC_PROIVDER_KEY));
    }
    try {
        currentDirectory = documentProvider
                .createFromUri(new URI(savedInstanceState.getString(CURRENT_DIRECTORY_KEY)));
    } catch (URISyntaxException e) {
        currentDirectory = documentProvider.getRootDirectory();
    }
    filterMode = savedInstanceState.getInt(FILTER_MODE_KEY, FileUtilities.ALL);
    viewMode = savedInstanceState.getInt(EXPLORER_VIEW_TYPE_KEY, GRID_VIEW);
    //openDirectory(currentDirectory);
    Log.d(LOGTAG, "onRestoreInstanceState");
    Log.d(LOGTAG, currentDirectory.toString() + Integer.toString(filterMode) + Integer.toString(viewMode));
}

From source file:com.nagravision.mediaplayer.FullscreenActivity.java

private void readInstanceState(Bundle in) {
    Log.v(LOG_TAG, "FullscreenActivity::readInstanceState - Enter\n");
    if (in != null) {
        Log.v(LOG_TAG, "FullscreenActivity::readInstanceState - in = " + in.toString() + "\n");
        if (!in.isEmpty()) {
            Log.v(LOG_TAG, "Reading SavedSTATE\n");
            if (in.containsKey("LastPosition")) {
                int position = in.getInt("LastPosition");
                Log.v(LOG_TAG, "SavedSTATE: LastPosition = " + mLastPosition + "\n");
                int msec = in.getInt("MediaPosition");
                Log.v(LOG_TAG, "SavedSTATE: MediaPosition = " + msec + "\n");
                ClickItem(position, msec);
            }/*from  ww w.j a v  a2 s .c  o  m*/
        } else {
            Log.v(LOG_TAG, "No SavedSTATE available ! Input bundle empty !\n");
        }
    } else {
        Log.v(LOG_TAG, "No SavedSTATE available ! Null Input bundle !\n");
    }
}

From source file:com.wareninja.android.opensource.oauth2login.common.Utils.java

/**
 * Connect to an HTTP URL and return the response as a string.
 * /*from w  w  w. j a  va2 s  . c om*/
 * 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
 * @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;

    if (method.equals("GET")) {
        url = url + "?" + encodeUrl(params);
    }
    if (AppContext.DEBUG)
        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));
             }
             */
            // YG: added this to avoid fups
            byte[] byteArr = null;
            try {
                byteArr = (byte[]) params.get(key);
            } catch (Exception ex1) {
            }
            if (byteArr != null)
                dataparams.putByteArray(key, byteArr);
        }

        // 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=\"" + 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());
    }
    if (AppContext.DEBUG)
        Log.d("Facebook-Util", method + " response: " + response);

    return response;
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java

private Intent handleMessageIntent(Intent intent, Bundle extras) {
    String action = extras.getString(ACTION);
    if (action != null && action.equals(DISMISS_NOTIFICATION)) {
        logger.debug("MFPPushIntentService:handleMessageIntent() - Dismissal message from GCM Server");
        dismissNotification(extras.getString(NID));
    } else {/*from  w ww.j a va2s .  com*/
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
        String messageType = gcm.getMessageType(intent);

        if (!extras.isEmpty()) {
            if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                logger.debug("MFPPushIntentService:handleMessageIntent() - Received a message from GCM Server."
                        + intent.getExtras());
                MFPInternalPushMessage message = new MFPInternalPushMessage(intent);
                intent = new Intent(MFPPushUtils.getIntentPrefix(getApplicationContext()) + GCM_MESSAGE);
                intent.putExtra(GCM_EXTRA_MESSAGE, message);

                if (!isAppForeground()) {
                    logger.debug(
                            "MFPPushIntentService:handleMessageIntent() - App is not on foreground. Queue the intent for later re-sending when app is on foreground");
                    intentsQueue.add(intent);
                }
                getApplicationContext().sendOrderedBroadcast(intent, null, resultReceiver, null,
                        Activity.RESULT_FIRST_USER, null, null);
            }
        }
    }
    return intent;
}

From source file:com.example.hjcyz1991.project407.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);
    String title = extras.getString("title");
    String inBody = new String(extras.getString("body"));
    if (body.contains(inBody)) {
        int idx = body.indexOf(inBody);
        if (idx != 0) {
            body.remove(inBody);//ww w .  j a  va 2  s  .c om
            body.add(0, inBody);
            if (body.size() > bodyLen)
                body.remove(bodyLen);
        }
    } else {
        body.add(0, inBody);
        if (body.size() > bodyLen)
            body.remove(bodyLen);
    }
    Log.d("GCM", body.toString());

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("GCM Notification", "Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("GCM Notification", "Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.
            for (int i = 0; i < 5; i++) {
                Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                }
            }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            sendNotification(title, inBody);
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:br.com.arlsoft.pushclient.PushClientModule.java

private void checkForExtras() {
    Activity activity = TiApplication.getAppRootOrCurrentActivity();
    if (activity != null) {
        Intent intent = activity.getIntent();
        if (intent != null) {
            Bundle extras = intent.getExtras();
            if (extras != null && !extras.isEmpty() && extras.containsKey(PROPERTY_EXTRAS)) {
                extras = extras.getBundle(PROPERTY_EXTRAS);
                HashMap data = PushClientModule.convertBundleToHashMap(extras);
                data.put("prev_state", "stopped");
                PushClientModule.sendMessage(data, PushClientModule.MODE_CLICK);
                intent.removeExtra(PROPERTY_EXTRAS);
            }//  w  w  w  . j av a 2  s.c  om
        }
    }
}

From source file:org.anhonesteffort.flock.EditAutoRenewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_PROGRESS);

    setContentView(R.layout.activity_edit_auto_renew);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setTitle(R.string.button_edit_payment_details);

    if (savedInstanceState != null && !savedInstanceState.isEmpty()) {
        if (!DavAccount.build(savedInstanceState.getBundle(KEY_DAV_ACCOUNT_BUNDLE)).isPresent()) {
            finish();/*from  w ww.j a  v  a2s .co  m*/
            return;
        }

        davAccount = DavAccount.build(savedInstanceState.getBundle(KEY_DAV_ACCOUNT_BUNDLE)).get();
        flockAccount = FlockAccount.build(savedInstanceState.getBundle(KEY_FLOCK_ACCOUNT_BUNDLE));
        cardInformation = FlockCardInformation.build(savedInstanceState.getBundle(KEY_CARD_INFORMATION_BUNDLE));
    } else if (getIntent().getExtras() != null) {
        if (!DavAccount.build(getIntent().getExtras().getBundle(KEY_DAV_ACCOUNT_BUNDLE)).isPresent()) {
            finish();
            return;
        }

        davAccount = DavAccount.build(getIntent().getExtras().getBundle(KEY_DAV_ACCOUNT_BUNDLE)).get();
        flockAccount = FlockAccount.build(getIntent().getExtras().getBundle(KEY_FLOCK_ACCOUNT_BUNDLE));
        cardInformation = FlockCardInformation
                .build(getIntent().getExtras().getBundle(KEY_CARD_INFORMATION_BUNDLE));
    }

    initCostPerYear();
}