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.meiste.tempalarm.gcm.GcmIntentService.java

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

    if (extras != null && !extras.isEmpty() && extras.containsKey(MSG_KEY)
            && GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
        final String type = extras.getString(MSG_KEY);
        final String state = extras.getString(STATE_KEY, "UNKNOWN");
        Timber.d("Received %s message with state %s", type, state);

        // Only show notification if user wants results notifications
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        final boolean ok2notify = prefs.getBoolean(AppConstants.PREF_NOTIFICATIONS, true);

        SyncAdapter.requestSync(this, ok2notify);

        if (ok2notify) {
            cancelNotification();//  w w  w .  ja  v  a  2  s . c  o m

            final Intent killIntent = new Intent(AppConstants.INTENT_ACTION_KILL_ALARM);
            LocalBroadcastManager.getInstance(this).sendBroadcastSync(killIntent);

            final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            final boolean inCall = tm.getCallState() != TelephonyManager.CALL_STATE_IDLE;

            switch (type) {
            case MSG_KEY_ALARM:
                handleAlarm(state, inCall);
                break;
            case MSG_KEY_SENSOR:
                handleSensor(state, inCall);
                break;
            default:
                Timber.i("Message type unknown. Ignoring.");
                break;
            }
        }
    }

    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:fr.mdk.kisspush.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);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*/*  w  w  w . jav 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_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)) {
            // Post notification of received message.
            sendNotification(extras.getString("msg"));
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.kalianey.oxapp.service.GcmBroadcastReceiver.java

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

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*/*from  w  w w.  j  a v a2s  .co  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 type = extras.getString(EXTRA_TYPE);
                String message = extras.getString(EXTRA_MESSAGE);
                String dataString = extras.getString("extra");

                //Build a conv to send to MessageView
                ModelConversation conversation = new ModelConversation();
                try {
                    JSONObject dataObj = new JSONObject(dataString); //{"senderId":3,"conversationId":2,"displayName":"Veda","recipientId":"1","message":"test again"}
                    conversation.setId(dataObj.getString("conversationId"));
                    conversation.setName(dataObj.getString("displayName"));
                    conversation.setPreviewText(message);
                    conversation.setOpponentId(dataObj.getString("senderId"));
                    conversation.setInitiatorId(dataObj.getString("recipientId"));

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                //Send notification
                String alert = "New message: " + message;
                sendNotification(context, alert);

                //Send to MessageFragment
                Intent broadcastIntent = new Intent();
                Bundle mBundle = new Bundle();
                mBundle.putSerializable("convObj", conversation);
                broadcastIntent.setAction("GCM_RECEIVED_ACTION");
                broadcastIntent.putExtra("conversation", mBundle);
                broadcastIntent.putExtra("gcm", message);
                context.sendBroadcast(broadcastIntent);

            }

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

From source file:com.example.rouge.anem.gcm.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);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*/*from  w ww  . ja va 2s. com*/
         * 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)) {

            sendNotification(extras.getString("price"));
            Log.i(TAG, extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.genesys.gms.demo.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);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//from  w  w 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_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)) {

            // Add your handler here (replacing sendNotification method)
            sendNotification("Received: " + extras.toString());

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

From source file:com.josetomastocino.siteupclient.app.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);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//from   w w  w  . ja  v  a2 s. co 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());

            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

            // Post notification of received message.
            sendNotification(extras.get("message").toString());
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:syncme.app.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);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*/*from  w  ww  . 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_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)) {

            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            sendNotification("type: " + extras.getString("type") + " data: " + extras.getString("data"));
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:org.cm.podd.report.service.GcmIntentService.java

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

    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {

        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            String payload = intent.getStringExtra("message");
            String payloadType = intent.getStringExtra("type");

            Log.i(TAG, String.format("Receive GCM message type=%s, payload type = %s extra=%s", messageType,
                    payloadType, payload));

            SharedPrefUtil pref = new SharedPrefUtil(getApplicationContext());
            if (pref.isUserLoggedIn() && payloadType != null) {
                if (payloadType.equals("news") || payloadType.equals("nearby")) {

                    String prefix = payloadType.equals("news") ? "?"
                            : "";

                    // Save notification
                    NotificationDataSource notificationDataSource = new NotificationDataSource(
                            getApplicationContext());

                    String strippedHtml = payload.replaceAll("<script.*?</script>", "");
                    String payloadStr = android.text.Html.fromHtml(strippedHtml).toString();

                    int len = 30;
                    if (payloadStr.length() < len) {
                        len = payloadStr.length();
                    }//  w w  w .ja v a  2s .co m
                    String title = prefix + ": " + payloadStr.substring(0, len) + "...";

                    long id = notificationDataSource.save(title, payload);
                    notificationDataSource.close();

                    // Post notification of received message.
                    sendNotification(id, title, payload);

                    // refresh notification list and drawer/actionbar counter
                    sendBroadcast(new Intent(HomeActivity.RECEIVE_MESSAGE_ACTION));

                } else if (payloadType.equals("followup")) {

                    // format => reportId@reportType@title@content
                    String[] arr = payload.split("@");
                    if (arr.length == 4) {
                        try {

                            long reportId = Long.parseLong(arr[0]);
                            long reportType = Long.parseLong(arr[1]);
                            String title = arr[2];
                            String message = arr[3];
                            FollowAlertService.notifyMessage(this, title, message, reportId, reportType);

                        } catch (NumberFormatException e) {
                            Log.e(TAG, String.format("Can't parse reportId or reporType [%s, %s]", arr[0],
                                    arr[1]));
                        }

                    } else {
                        Log.e(TAG, String.format("Argument mismatch: require 4 get %d", arr.length));
                    }

                } else if (payloadType.equals("updated_report_type")) {
                    ReportQueueDataSource dataSource = new ReportQueueDataSource(getApplicationContext());
                    dataSource.addUpdateTypeQueue();
                    dataSource.close();

                    // Broadcasts the Intent to network receiver
                    Intent updateIntent = new Intent(DataSubmitService.ACTION_REPORT_SUBMIT);
                    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(updateIntent);
                } else {
                    Log.e(TAG, String.format("Unhandle gcm message: type = %s, message = %s", payloadType,
                            payload));
                }
            }

        }
    }
}

From source file:com.herokuapp.pushdemoandroid.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);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//from   w  ww .j a  va2 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());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // Post notification of received message.
            sendNotification("Received: " + extras.toString());
            String message = intent.getExtras().getString("message");

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

From source file:edu.sjsu.jobfair.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.i("A.GcmIntentService", "In onHandleIntent()");
    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);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//from   w ww  . ja va 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_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)) {
            // Post notification of received message.
            String title = extras.getString("title");
            String message = extras.getString("message");
            sendNotification(title + ": " + message);
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}