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:treehou.se.habit.gcm.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();

    if (extras == null) {
        return;/* w w  w  .  j a v  a 2 s  .co m*/
    }

    int notificationId;
    if (mNotificationManager == null) {
        mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    }

    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    String gcmType = gcm.getMessageType(intent);
    Log.d(TAG, "Message type = " + gcmType);
    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(gcmType)) {
            // If this is notification, create new one
            if (!intent.hasExtra("notificationId")) {
                notificationId = 1;
            } else {
                notificationId = Integer.parseInt(intent.getExtras().getString("notificationId"));
            }
            String messageType = intent.getExtras().getString("type");
            if (messageType != null && messageType.equals("notification")) {
                sendNotification(intent.getExtras().getString("message"), notificationId);
                // If this is hideNotification, cancel existing notification with it's id
            } else if (messageType != null && messageType.equals("hideNotification")) {
                mNotificationManager.cancel(Integer.parseInt(intent.getExtras().getString("notificationId")));
            }
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.landa.backend.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    String usertype = intent.getStringExtra("user");
    String action = intent.getStringExtra("action");

    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//  ww  w. j a  va  2 s  .  c  om
         * 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("Send error: " + extras.toString(), "");
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("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.
            //Log.i(TAG, "Message is" + usertype + action);
            for (int i = 0; i < 5; i++) {
                Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                try {
                    Thread.sleep(250);
                } catch (InterruptedException e) {
                }
            }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            // TODO: add other users
            if (usertype.equals("cook")) {
                Log.i(TAG, "Sending to cook activity");
                CookOrderToActivity();
            }
            if (usertype.equals("waitstaff")) {
                if (action.equals("refill")) {
                    String table = intent.getStringExtra("table");
                    RefillToActivity(table);
                    sendNotification("Table " + table + " would like a refill.", table);
                }
                if (action.equals("help")) {
                    String table = intent.getStringExtra("table");
                    HelpToActivity(table);
                    sendNotification("Table " + table + " requests help.", table);
                }
                if (action.equals("refresh")) {
                    RefreshWait();

                }
            }
            if (usertype.equals("customer")) {
                if (action.equals("readytopay")) {
                    readyToPay();
                }
                if (action.equals("chat")) {
                    String tableFrom = intent.getStringExtra("tableFrom");
                    String msg = intent.getStringExtra("msg");
                    chat(tableFrom, msg);
                }
            }

            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReciever.completeWakefulIntent(intent);
}

From source file:com.facebook.android.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//  ww  w .  j a  v  a  2  s . c o  m
 * @throws MalformedURLException - if the URL format is invalid
 * @throws IOException - if a network problem occurs
 */
@Deprecated
public static String openUrl(String url, String method, Bundle params) throws 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);
    }
    Utility.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()) {
            Object parameter = params.get(key);
            if (parameter instanceof byte[]) {
                dataparams.putByteArray(key, (byte[]) parameter);
            }
        }

        // 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());

        try {
            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();
        } finally {
            os.close();
        }
    }

    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.example.wojtekswiderski.woahpaper.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);

    word = extras.get("word").toString();
    sender = extras.get("sender").toString();

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//from   w  w w .  j  av a2  s .c o  m
         * 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("Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

            int results = numberResults();

            if (results > MAXRESULTS) {
                int start;
                int i = 0;
                do {
                    start = (int) (Math.random() * MAXRESULTS);
                    i++;
                } while (setWallPaper(start) && i <= 10);
            } else {
                int i = 0;
                do {
                    i++;
                } while (setWallPaper(i) && i <= 10);
            }

            sendNotification("Received " + word.substring(0, 1).toUpperCase() + word.substring(1) + " from "
                    + sender.substring(0, 1).toUpperCase() + sender.substring(1));
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:org.akvo.caddisfly.sensor.ec.CalibrateSensorActivity.java

@SuppressWarnings("SameParameterValue")
private void startService(Class<?> service, ServiceConnection serviceConnection, @Nullable Bundle extras) {

    if (!UsbService.SERVICE_CONNECTED) {
        Intent startService = new Intent(this, service);
        if (extras != null && !extras.isEmpty()) {
            Set<String> keys = extras.keySet();
            for (String key : keys) {
                String extra = extras.getString(key);
                startService.putExtra(key, extra);
            }/* ww w.  ja  va 2 s.c o  m*/
        }
        startService(startService);
    }
    Intent bindingIntent = new Intent(this, service);
    bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);

    deviceStatus = 0;

    handler.postDelayed(validateDeviceRunnable, 100);

}

From source file:com.sample.facebook.Util.java

/**
 * Connect to an HTTP URL and return the response as a string.
 * /*from  www .j a  va 2 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);
    }
    Log.d("Facebook-Util", method + " URL: " + url);
    //url+="&fields=email";
    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.setConnectTimeout(45000);
        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:org.site_monitor.activity.SiteSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    String url = getIntent().getStringExtra(P_SITE_SETTINGS);
    if (url == null) {
        Toast.makeText(this, R.string.site_not_found, Toast.LENGTH_SHORT).show();
        finish();//from  w ww . j a v  a 2 s  .  c  o m
    }
    dbHelper = DBHelper.getHelper(context);
    if (savedInstanceState == null || savedInstanceState.isEmpty()) {
        try {
            FavIconService.enqueueLoadFavIcoWork(this, url);
            SiteSettings dbSiteSettings = dbHelper.getDBSiteSettings().findForHost(url);
            if (dbSiteSettings == null) {
                Toast.makeText(this, R.string.site_not_found, Toast.LENGTH_SHORT).show();
                finish();
            }
            siteSettings = new SiteSettingsBusiness(dbSiteSettings);
        } catch (SQLException e) {
            Log.e(TAG, "search for host", e);
            Toast.makeText(this, R.string.site_not_found, Toast.LENGTH_SHORT).show();
            finish();
        }
    } else {
        siteSettings = savedInstanceState.getParcelable(PARCEL_SITE);
    }
    setTitle(siteSettings.getName());
    setContentView(R.layout.activity_site_settings);

    FragmentManager fragmentManager = getSupportFragmentManager();
    siteSettingsFragment = (SiteSettingsActivityFragment) fragmentManager.findFragmentByTag(TAG_TASK_FRAGMENT);
    if (siteSettingsFragment == null) {
        siteSettingsFragment = (SiteSettingsActivityFragment) fragmentManager
                .findFragmentById(R.id.fragment_site_settings);
    }
    siteSettingsFragment.setSiteSettings(siteSettings);
}

From source file:com.mbientlab.metawear.app.CustomFragment.java

private void startService(Class<?> service, ServiceConnection serviceConnection, Bundle extras) {
    if (!UsbService.SERVICE_CONNECTED) {
        Intent startService = new Intent(getActivity(), service);
        if (extras != null && !extras.isEmpty()) {
            Set<String> keys = extras.keySet();
            for (String key : keys) {
                String extra = extras.getString(key);
                startService.putExtra(key, extra);
            }/*from ww  w  . ja v  a 2 s.c o  m*/
        }
        getActivity().startService(startService);
    }
    Intent bindingIntent = new Intent(getActivity(), service);
    getActivity().bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);
}

From source file:com.mch.registry.ccs.app.GcmIntentService.java

@Override
///New: Mueller//from w w w.j a  va2  s.  c o m
protected void onHandleIntent(Intent intent) {
    mSenderId = Constants.PROJECT_ID;
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    // action handling for actions of the activity
    String action = intent.getAction();
    Log.v("PregnancyGuide", "action: " + action);
    if (action.equals(Constants.ACTION_REGISTER)) {
        register(gcm, intent);
    } else if (action.equals(Constants.ACTION_UNREGISTER)) {
        unregister(gcm, intent);
    } else if (action.equals(Constants.ACTION_ECHO)) {
        sendMessage(gcm, intent);
    }

    // handling of stuff as described on
    // http://developer.android.com/google/gcm/client.html
    try {
        Bundle extras = intent.getExtras();
        // The getMessageType() intent parameter must be the intent you
        // received in your BroadcastReceiver.
        String messageType = gcm.getMessageType(intent);

        if (extras != null && !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)) {
                sendPhoneActivityNotification("Send error: " + extras.toString(), "Error");
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
                sendPhoneActivityNotification("Deleted messages on server: " + extras.toString(), "Deleted");
                // If it's a regular GCM message, do some work.
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                // Post notification of received message.
                String msg = extras.getString("message");
                PregnancyDataHandler pdh = new PregnancyDataHandler(getApplicationContext(), "fn received",
                        null, 1);
                Pregnancy preg = pdh.getPregnancy();

                if (TextUtils.isEmpty(msg)) {
                } else if (msg.contains("_R: ")) {
                    final String recommendationMessage = msg.replaceAll("_R: ", "");
                    Handler mHandler = new Handler(getMainLooper());
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            RecommendationDataHandler rdh = new RecommendationDataHandler(
                                    getApplicationContext(), "Msg received", null, 1);
                            Calendar cal = Calendar.getInstance();
                            rdh.addRecommendation(recommendationMessage,
                                    Utils.getPregnancyDay(getApplicationContext()), cal.getTime(),
                                    Utils.getPregnancyWeek(getApplicationContext()));
                            sendNotification(getString(R.string.notification_text_new_recommendation),
                                    getString(R.string.app_name));
                        }
                    });
                } else if (msg.contains("_V: ")) {
                    final String visitMessage = msg.replaceAll("_V: ", "");
                    Handler mHandler = new Handler(getMainLooper());
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            VisitDataHandler vdh = new VisitDataHandler(getApplicationContext(), "Msg received",
                                    null, 1);
                            vdh.addVisit(visitMessage);
                            sendNotification(getString(R.string.notification_text_new_visit),
                                    getString(R.string.app_name));
                        }
                    });
                } else if (msg.contains("_Verified")) {
                    Handler mHandler = new Handler(getMainLooper());
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            PregnancyDataHandler pdh = new PregnancyDataHandler(getApplicationContext(),
                                    "Msg received", null, 1);
                            Toast.makeText(getApplicationContext(), getString(R.string.application_ready),
                                    Toast.LENGTH_LONG).show();
                            pdh.setVerified(true);
                            pdh.setLoadingProgress(pdh.getPregnancy().get_loadingProgress() + 1);
                        }
                    });
                } else if (msg.contains("_NotVerified")) {
                    Handler mHandler = new Handler(getMainLooper());
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            PregnancyDataHandler pdh = new PregnancyDataHandler(getApplicationContext(),
                                    "not verified", null, 1);
                            pdh.setVerified(false);
                            Toast.makeText(getApplicationContext(), getString(R.string.number_not_verified),
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                } else if (msg.contains("_PregnancyNotFound")) {
                    Handler mHandler = new Handler(getMainLooper());
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            PregnancyDataHandler pdh = new PregnancyDataHandler(getApplicationContext(),
                                    "Msg received", null, 1);
                            pdh.setVerified(false);
                            Toast.makeText(getApplicationContext(), getString(R.string.number_not_found),
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                } else if (msg.contains("_PregnancyInfosFacilityName")) {
                    String pInfoFN = msg.replaceAll("_PregnancyInfosFacilityName: ", "");
                    pdh.updateFacilityName(pInfoFN);
                    pdh.setLoadingProgress(preg.get_loadingProgress() + 1);
                } else if (msg.contains("_PregnancyInfosFacilityPhone")) {
                    String pInfoFP = msg.replaceAll("_PregnancyInfosFacilityPhone: ", "");
                    pdh.updateFacilityPhone(pInfoFP);
                    pdh.setLoadingProgress(preg.get_loadingProgress() + 1);
                } else if (msg.contains("_PregnancyInfosExpectedDelivery")) {
                    String pInfoED = msg.replaceAll("_PregnancyInfosExpectedDelivery: ", "");
                    pdh.updateExpectedDelivery(pInfoED);
                    pdh.setLoadingProgress(preg.get_loadingProgress() + 1);
                } else if (msg.contains("_PregnancyInfosPatientName")) {
                    String pInfoPN = msg.replaceAll("_PregnancyInfosPatientName: ", "");
                    pdh.updatePatientName(pInfoPN);
                    pdh.setLoadingProgress(preg.get_loadingProgress() + 1);
                }

                Log.i("PregnancyGuide", "Received: " + extras.toString());
            }
        }
    } finally {
        // Release the wake lock provided by the WakefulBroadcastReceiver.
        GcmBroadcastReceiver.completeWakefulIntent(intent);
    }
}

From source file:com.cygnus.honda.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    prefs = getSharedPreferences(LoginActivity.MY_PREFS_NAME, MODE_PRIVATE);
    editor = getSharedPreferences(LoginActivity.MY_PREFS_NAME, MODE_PRIVATE).edit();

    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);
    Log.i("Notification received", "Thanks");

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle

        // Post notification of received message.
        // sendNotification("Received: " + extras.toString());
        String[] separated = extras.getString("message").split(":");
        if (separated[0].equals("0")) {

            if (separated.length == 3) {

                editor.putString("refreshcontact" + separated[1], separated[1]);

                editor.commit();//from  ww w .ja va2  s. com

                sendNotification(separated[2]);

            } else {

                editor.putString("refreshcontact" + separated[1], separated[1]);
                editor.commit();

                sendNotification(separated[2] + " : " + separated[3]);
            }

            Intent intent1 = new Intent();
            intent1.putExtra("message_received", extras.getString("message"));
            intent1.setAction("com.cygnus.honda.blinkled");
            sendBroadcast(intent1);

        } else if (separated[0].equals("2")) {
            // sendNotification(extras.getString("message"));

            LoginActivity.checkNotifyCountReceive = true;
            Intent intent1 = new Intent();
            intent1.putExtra("message_received", extras.getString("message"));
            intent1.setAction("com.cygnus.honda.blinkledcontact");
            sendBroadcast(intent1);

            if (separated.length == 3) {
                sendNotification(separated[2]);

            }

        }

        else {
            sendNotification(extras.getString("message"));

        }

        LoginActivity.checkNotifyCountReceive = true;

        Log.i(TAG, "Received: " + extras.toString());
    }

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}