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:ro.astazi.andrapp.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);

    Log.i(TAG, "GcmIntentService IntentService");

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*/*from w  w w. ja 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", "Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages", "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(extras.getString("title"), extras.getString("message"));
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.example.isaac.nileswestlitcenter.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
        /*//  ww w .  jav a2s . 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)) {

        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {

            // 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.

        }
        if (extras.getString("subject") != null) {
            if (intent.getExtras().getString("delete") != null) {
                if (((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE))
                        .inKeyguardRestrictedInputMode()) {
                    //delete from arraylist
                    for (int i = 0; i < storeWhileScreenOff.size(); i++) {
                        if (storeWhileScreenOff.get(i)[1] == extras.getString("subject")
                                && storeWhileScreenOff.get(i)[2] == extras.getString("name")) {
                            storeWhileScreenOff.remove(i);
                            return;
                        }
                    }
                    //not in stored list, but on screen
                    storeWhileScreenOff.add(
                            new String[] { "true", extras.getString("subject"), extras.getString("name") });
                } else {
                    sendMessage(true, extras.getString("subject"), extras.getString("name"));
                    //                    MainActivity.deleteStudentFromList(extras.getString("subject"),extras.getString("name"));
                    //                   or MainActivity.delete(extras.getInt("id"));
                }
            } else {
                if (((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE))
                        .inKeyguardRestrictedInputMode()) {
                    storeWhileScreenOff.add(
                            new String[] { "false", extras.getString("subject"), extras.getString("name") });
                } else {
                    sendMessage(false, extras.getString("subject"), extras.getString("name"));
                }
                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
                // Post notification of received message.
                sendNotification(extras.getString("subject"), extras.getString("name"));
                Vibrator v = (Vibrator) this.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
                // Vibrate for 500 milliseconds
                v.vibrate(1000);
                ((PowerManager) getSystemService(POWER_SERVICE))
                        .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                                "TAG")
                        .acquire();
                Log.i(TAG, "Received: " + extras.toString());

            }

        }
    }

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

From source file:net.omplanet.starwheel.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  ww  .ja  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)) {
            Log.i(Consts.TAG, "onHandleIntent: message error");
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.i(Consts.TAG, "onHandleIntent: message deleted");
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            String subId = intent.getStringExtra(GCM_KEY_SUBID);
            Log.i(Consts.TAG, "onHandleIntent: subId: " + subId);
            String[] tokens = subId.split(":");
            String typeId = tokens[1];

            // dispatch message
            if (GCM_TYPEID_QUERY.equals(typeId)) {
                Intent messageIntent = new Intent(BROADCAST_ON_MESSAGE);
                messageIntent.putExtras(intent);
                messageIntent.putExtra("token", tokens[2]);
                boolean isReceived = LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);

                //Send push notification if the application did not receive the broadcast.
                if (!isReceived) {
                    Log.i(Consts.TAG, "A message has been recieved but no broadcast was handled.");
                    NotificationUtil.generateNotification(this, intent);
                } else {
                    Log.i(Consts.TAG, "A message has been recieved, broadcasted and handled.");
                }
            }
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GCMBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.example.week04.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 a2 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)) {
            // TODO :: check wifi-stat                
            // Receive articles, and post notification of received message.
            String keyword = extras.getString("new data");
            getArticleInBackground(keyword);

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

From source file:jp.januaraid.android.synciteasy.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
        /*//w  ww . ja 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)) {
            Log.i(Consts.TAG, "onHandleIntent: message error");
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.i(Consts.TAG, "onHandleIntent: message deleted");
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            String subId = intent.getStringExtra(GCM_KEY_SUBID);
            Log.i(Consts.TAG, "onHandleIntent: subId: " + subId);
            String[] tokens = subId.split(":");
            String typeId = tokens[1];

            // dispatch message
            if (GCM_TYPEID_QUERY.equals(typeId)) {
                Intent messageIntent = new Intent(BROADCAST_ON_MESSAGE);
                messageIntent.putExtras(intent);
                messageIntent.putExtra("token", tokens[2]);
                LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
                Log.i(Consts.TAG, ":sendBroadcast");
                // 
                String accountName = getApplicationContext()
                        .getSharedPreferences(Consts.PREF_KEY_CLOUD_BACKEND, Context.MODE_PRIVATE)
                        .getString(Consts.PREF_KEY_ACCOUNT_NAME, null);
                Account account = null;
                if (accountName == null) {
                    return;
                } else {
                    account = new Account(accountName, Consts.ACCOUNT_TYPE);
                }
                Bundle settingsBundle = new Bundle();
                settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
                settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
                settingsBundle.putString("token", tokens[2]);
                ContentResolver.requestSync(account, Consts.AUTHORITY, settingsBundle);
            }
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GCMBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.grokkingandroid.sampleapp.samples.gcm.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    mSenderId = getResources().getString(R.string.gcm_project_id);
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    // action handling for actions of the activity
    String action = intent.getAction();
    Log.v("grokkingandroid", "action: " + action);
    if (action.equals(Constants.ACTION_REGISTER)) {
        register(gcm, intent);/*from  w ww  .ja v  a2 s .  c o m*/
    } 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)) {
                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 msg = extras.getString("message");
                if (TextUtils.isEmpty(msg)) {
                    msg = "empty message";
                }
                sendNotification(msg);
                Log.i("grokkingandroid", "Received: " + extras.toString() + ", sent: " + msg);
            }
        }
    } finally {
        // Release the wake lock provided by the WakefulBroadcastReceiver.
        GcmBroadcastReceiver.completeWakefulIntent(intent);
    }
}

From source file:com.sentaroh.android.Utilities.Dialog.MessageDialogFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (DEBUG_ENABLE)
        Log.v(APPLICATION_TAG, "onSaveInstanceState terminateRequired=" + terminateRequired);
    if (outState.isEmpty()) {
        outState.putBoolean("WORKAROUND_FOR_BUG_19917_KEY", true);
    }//from  w  w  w.j  a  v  a 2s.co m
}

From source file:org.spaceappschallenge.spacemission.roadmap.mgf.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 != null && !extras.isEmpty()) { // has effect of unparcelling Bundle
        /*/*w w w  .  j  a  va  2  s  .  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)) {
            Log.e(TAG, "Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.w(TAG, "Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

            final Mission mission = new Mission();

            Object messageProperty;

            messageProperty = extras.get("title");

            if (messageProperty != null) {
                mission.title = messageProperty.toString();
            }

            messageProperty = extras.get("summary");

            if (messageProperty != null) {
                mission.summary = messageProperty.toString();
            }

            messageProperty = extras.get("description");

            if (messageProperty != null) {
                mission.description = messageProperty.toString();
            }

            messageProperty = extras.get("image");

            if (messageProperty != null) {
                mission.image = messageProperty.toString();
            }

            messageProperty = extras.get("url");

            if (messageProperty != null) {
                mission.url = messageProperty.toString();
            }

            messageProperty = extras.get("date");

            if (messageProperty != null) {
                //                    mission.date = messageProperty.toString();
                Log.i(TAG, messageProperty.toString());
            }

            sendNotification(mission);

            Log.i(TAG, mission.toString());

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

From source file:net.vidainc.vidahome.service.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    mSenderId = getResources().getString(R.string.gcm_project_id);
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    // action handling for actions of the activity
    String action = intent.getAction();
    switch (action) {
    case Constants.ACTION_REGISTER:
        register(gcm);/*from  w ww. j a  v a2s . c om*/
        break;
    case Constants.ACTION_UNREGISTER:
        unregister(gcm, intent);
        break;
    case Constants.ACTION_BEACON_DATA:
        sendBeaconData(gcm, intent);
        break;
    }

    // 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)) {
                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.d("BENCHMARK", "MESSAGE RECEIVED AT: " + System.nanoTime());
                // Post notification of received message.
                String msg = extras.getString("message");
                if (TextUtils.isEmpty(msg)) {
                    msg = "empty message";
                }
                sendNotification(msg);
                Log.i("vida_home", "Received: " + extras.toString() + ", sent: " + msg);
            }
        }
    } finally {
        // Release the wake lock provided by the WakefulBroadcastReceiver.
        GcmBroadcastReceiver.completeWakefulIntent(intent);
    }
}

From source file:sg.togoparts.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.
    Log.d(TAG, "dskajflsk");
    String messageType = gcm.getMessageType(intent);
    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            sendNotification(extras);//from  ww w .j a va 2  s .  c o m
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}