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.gcmex.GcmIntentService.java

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

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        String messageType = gcm.getMessageType(intent);
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            GCM.receiveMessage("MESSAGE_TYPE_SEND_ERROR", extras);
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            GCM.receiveMessage("MESSAGE_TYPE_DELETED", extras);
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            GCM.receiveMessage("MESSAGE_TYPE_MESSAGE", extras);
        }// w w  w .j  ava  2 s .  c  om
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:in.udacity.learning.gcm.MyGcmListenerService.java

/**
 * Called when message is received.//  w w w  .j av a 2s  .c  om
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
@Override
public void onMessageReceived(String from, Bundle data) {
    // Time to unparcel the bundle!
    if (!data.isEmpty()) {
        // TODO: gcm_default sender ID comes from the API console
        String senderId = getString(R.string.gcm_defaultSenderId);
        if (senderId.length() == 0) {
            Toast.makeText(this, "SenderID string needs to be set", Toast.LENGTH_LONG).show();
        }
        // Not a bad idea to check that the message is coming from your server.
        if ((senderId).equals(from)) {
            // Process message and then post a notification of the received message.
            try {

                //String d = data.getString(EXTRA_DATA);

                String d2 = data.toString();
                d2 = d2.replace("Bundle", "");
                JSONArray jsonArray = new JSONArray(d2);
                JSONObject jsonObject = jsonArray.getJSONObject(0);

                String weather = jsonObject.getString(EXTRA_WEATHER);
                String location = jsonObject.getString(EXTRA_LOCATION);
                String alert = String.format(getString(R.string.gcm_weather_alert), weather, location);
                sendNotification(alert);
            } catch (JSONException e) {
                Log.e(TAG, e.toString());
            }
        }
        Log.i(TAG, "Received: " + data.toString());
    }
}

From source file:com.liferay.alerts.service.PushNotificationService.java

@Override
protected void onHandleIntent(Intent intent) {
    GoogleCloudMessaging gcm = GCMUtil.getGoogleCloudMessaging(this);

    String type = gcm.getMessageType(intent);
    Bundle extras = intent.getExtras();

    if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(type) && !extras.isEmpty()) {

        try {/*w  ww.j  a v  a  2  s .  c  o  m*/
            User user = new User(extras.getString("fromUser"));
            Alert alert = new Alert(user, extras.getString(Alert.PAYLOAD));

            _insert(user, alert);
            _addCard(alert);
        } catch (JSONException je) {
        }
    }

    PushNotificationReceiver.completeWakefulIntent(intent);
}

From source file:org.peercast.core.Channel.java

public List<Servent> getServents() {
    if (servents == null) {
        servents = new ArrayList<Servent>();
        Bundle bServent = mBundle.getBundle("servent");
        while (bServent != null && !bServent.isEmpty()) {
            servents.add(new Servent(bServent));
            bServent = bServent.getBundle("next");
        }/*from w  ww  .  j a v a 2s  .c  om*/
    }
    return servents;
}

From source file:com.gcm.lib.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()) {
        sendNotification(extras.toString(), messageType);
    }//from   w  w  w  .j ava  2 s .c  o m
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.liferay.alerts.receiver.PushNotificationIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    GoogleCloudMessaging gcm = GCMUtil.getGoogleCloudMessaging(this);

    String type = gcm.getMessageType(intent);
    Bundle extras = intent.getExtras();

    if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(type) && !extras.isEmpty()) {

        try {// w  w  w.jav a 2s  .co m
            long parentPushNotificationsEntryId = Long
                    .parseLong(extras.getString(Alert.PARENT_PUSH_NOTIFICATIONS_ENTRY_ID));

            if (parentPushNotificationsEntryId != 0) {
                return;
            }

            long id = Long.parseLong(extras.getString(Alert.PUSH_NOTIFICATIONS_ENTRY_ID));

            JSONObject userJSONObject = new JSONObject(extras.getString(Alert.USER));

            User user = new User(userJSONObject);

            JSONObject payload = new JSONObject(extras.getString(Alert.PAYLOAD));

            Alert alert = new Alert(id, user, payload);

            _insert(user, alert);

            NotificationUtil.notifyUnreadAlerts(this);
            MainActivity.addCard(this, alert);
        } catch (JSONException je) {
            Log.e(_TAG, "Couldn't parse alert JSON.", je);
        } finally {
            PushNotificationReceiver.completeWakefulIntent(intent);
        }
    }
}

From source file:org.onepf.opfpush.gcm_migrate_sample.GCMIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    String messageType = BroadcastMessageListener.getMessageType(intent);
    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*//from w  ww.  ja va2s  . 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_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.
            for (int i = 0; i < 5; i++) {
                Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException ignored) {
                }
            }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            sendNotification("Received: " + extras.toString());
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GCMBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:no.digipost.android_push.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_MESSAGE.equals(messageType)) {
            String message = extras.getString("message");
            String timestamp = extras.getString("timestamp");

            sendNotification(message + "\n" + timestamp);
        }/* w  w w .j ava  2s  . c  o  m*/
    }

    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.activiti.android.ui.fragments.builder.AlfrescoFragmentBuilder.java

public AlfrescoFragmentBuilder addExtra(Bundle b) {
    if (b == null || b.isEmpty()) {
        return this;
    }//w w w.j av a  2 s . c  om
    if (extraConfiguration == null) {
        this.extraConfiguration = b;
    } else {
        extraConfiguration.putAll(b);
    }
    return this;
}

From source file:com.kakao.authorization.accesstoken.GetterAccessToken.java

private BoundRequestBuilder makeAccessTokenRequest() {
    final BoundRequestBuilder requestBuilder = HttpRequestTask.ASYNC_HTTP_CLIENT.preparePost(
            HttpRequestTask.createBaseURL(ServerProtocol.AUTH_AUTHORITY, ServerProtocol.ACCESS_TOKEN_PATH));
    final Entry<String, String> entry = HttpRequestTask.KA_HEADER.entrySet().iterator().next();
    requestBuilder.addHeader(entry.getKey(), entry.getValue());

    if (accessTokenRequest.isAccessTokenRequestWithAuthCode()) {
        requestBuilder.addQueryParameter(ServerProtocol.GRANT_TYPE_KEY,
                ServerProtocol.GRANT_TYPE_AUTHORIZATION_CODE);
        requestBuilder.addQueryParameter(ServerProtocol.CODE_KEY, accessTokenRequest.getAuthorizationCode());
        requestBuilder.addQueryParameter(ServerProtocol.REDIRECT_URI_KEY, accessTokenRequest.getRedirectURI());
    } else { //if(request.isAccessTokenRequestWithRefreshToken()) {
        requestBuilder.addQueryParameter(ServerProtocol.GRANT_TYPE_KEY, ServerProtocol.REFRESH_TOKEN_KEY);
        requestBuilder.addQueryParameter(ServerProtocol.REFRESH_TOKEN_KEY,
                accessTokenRequest.getRefreshToken());
    }/*  ww  w  . j  a va 2 s .  co  m*/
    requestBuilder.addQueryParameter(ServerProtocol.CLIENT_ID_KEY, accessTokenRequest.getAppKey());
    requestBuilder.addQueryParameter(ServerProtocol.ANDROID_KEY_HASH, accessTokenRequest.getKeyHash());

    final Bundle extraParams = accessTokenRequest.getExtras();
    if (extraParams != null && !extraParams.isEmpty()) {
        for (String key : extraParams.keySet()) {
            String value = extraParams.getString(key);
            if (value != null) {
                requestBuilder.addQueryParameter(key, value);
            }
        }
    }
    return requestBuilder;
}