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.example.android.sunshine.app.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {

        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

            String weather = extras.getString(EXTRA_WEATHER);
            String location = extras.getString(EXTRA_LOCATION);
            String alert = "Heads up: " + weather + " in " + location + "!";

            sendNotification(context, alert);

            Log.i(LOG_TAG, "Received: " + extras.toString());
        }/*from   w  w  w.  j av a2  s  .  c o  m*/
    }
}

From source file:trogdor.itemhunter.mobileapp.GcmIntentService.java

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

    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            if (extras.getString(KEY_NOTIF_TYPE).equals(TYPE_OUTBID)) {
                sendOutbidNotification(extras);
            } else if (extras.getString(KEY_NOTIF_TYPE).equals(TYPE_CUSTOM)) {
                displayNotification(extras.getString(KEY_CUSTOM_MSG), null);
            }//from   ww  w .  j ava2 s  . co  m
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            displayNotification("Send error: " + extras.toString(), null);
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            displayNotification("Deleted messages on server: " + extras.toString(), null);
        }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.mozilla.simplepush.simplepushdemoapp.GcmIntentService.java

/** Handle the new event.
 *
 * @param intent GCM message recv'd// w w  w.j a  v  a 2  s . c  o m
 */
@Override
protected void onHandleIntent(Intent intent) {
    // getExtras contains the data from the remote server.
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    String messageType = gcm.getMessageType(intent);
    if (!extras.isEmpty()) {
        String msg;
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            msg = "Send error: " + extras.toString();
            Log.e(TAG, msg);
            displayNotification(extras);
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            msg = "Deleted messages on server: " + extras.toString();
            Log.e(TAG, msg);
            displayNotification(extras);
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            displayNotification(extras);
            msg = "Recv'd" + extras.toString();
            Log.i(TAG, msg);
        }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.example.android.sunshine.app.gcm.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {

        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // Is this our message?? Better be if you're going to act on it!
            if (MainActivity.PROJECT_NUMBER.equals(extras.getString(EXTRA_SENDER))) {
                // Process message and then post a notification of the received message.
                String weather = extras.getString(EXTRA_WEATHER);
                String location = extras.getString(EXTRA_LOCATION);
                String alert = "Heads up: " + weather + " in " + location + "!";

                sendNotification(context, alert);
            }/*w  w w.  j  a  v a2  s .c o m*/

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

From source file:de.teamklinge.mymusicteacher.gcm.GcmIntentService.java

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

    if (!extras.isEmpty()) {
        // Nachrichten Filtern
        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());

            // Regulre Nachricht
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

            // Android-Notification
            sendNotification("Schler X hat Interesse an Ihr Unterrichtsangebot!");
            Log.i(TAG, "Received: " + extras.toString());
        }/*from   w  w w . j  av  a2 s  . c o m*/
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.chrismorais.android.sunshine.app.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//from  ww w .  java2  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_MESSAGE.equals(messageType)) {
            // Is this our message?? Better be if you're going to act on it!
            if (MainActivity.PROJECT_NUMBER.equals(extras.getString(EXTRA_SENDER))) {
                // Process message and then post a notification of the received message.
                String weather = extras.getString(EXTRA_WEATHER);
                String location = extras.getString(EXTRA_LOCATION);
                String alert = "Heads up: " + weather + " in " + location + "!";

                sendNotification(context, alert);
            }

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

From source file:app.com.ark.android.sunshine.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//from w  w  w. java2  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_MESSAGE.equals(messageType)) {
            // Is this our message?? Better be if you're going to act on it!
            if (MainActivity.PROJECT_NUMBER.equals(extras.getString(EXTRA_SENDER))) {
                // Process message and then post a notification of the received message.
                String weather = extras.getString(EXTRA_WEATHER);
                String location = extras.getString(EXTRA_LOCATION);
                String alert = "Heads up: " + weather + " in " + location + "!";

                sendNotification(context, alert);
            }

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

From source file:tm.alashow.dotjpg.android.gcm.PushNotificationsService.java

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

    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            U.l("Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            U.l("Message is deleted");
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            U.l("Normal message received! Showing notification..");
            showNotification(getApplicationContext(), intent);
        }//from  w w w.  j a  va  2s  . c o  m
    }
    GCMReceiver.completeWakefulIntent(intent);
}

From source file:com.example.hellonetwork.GcmIntentService.java

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

    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {

        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)) {

            for (int i = 0; i < loop; i++) {
                Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                try {
                    Thread.sleep(sleep);
                } catch (InterruptedException e) {
                    Log.i("INTERRUPT", " ");
                }//from www.  j ava  2  s.c  om
            }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());

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

    GcmReceiver.completeWakefulIntent(intent);
}

From source file:com.nzsoft.myweather.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//from   ww  w .  j a v  a  2  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_MESSAGE.equals(messageType)) {
            // Is this our message?? Better be if you're going to act on it!
            Log.d(LOG_TAG, "extras.getString(EXTRA_SENDER)" + extras.getString(EXTRA_SENDER));
            if (MainActivity.PROJECT_NUMBER.equals(extras.getString(EXTRA_SENDER))) {
                Log.d(LOG_TAG, "onReceive if send notif");
                // Process message and then post a notification of the received message.
                String weather = extras.getString(EXTRA_WEATHER);
                String location = extras.getString(EXTRA_LOCATION);
                String alert = "Heads up: " + weather + " in " + location + "!";

                sendNotification(context, alert);
            }

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