Example usage for android.os Bundle getString

List of usage examples for android.os Bundle getString

Introduction

In this page you can find the example usage for android.os Bundle getString.

Prototype

@Nullable
public String getString(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:RhodesService.java

private void handlePushMessage(String pushType, Bundle extras) {
    Logger.D(TAG, "Handle PUSH message");

    if (extras == null) {
        Logger.W(TAG, "Empty PUSH message received");
        return;/*from  w  ww  .  j a va  2 s  .c o m*/
    }

    String phoneId = extras.getString("phone_id");
    if (phoneId != null && phoneId.length() > 0 && !phoneId.equals(this.getPhoneId().toString())) {
        Logger.W(TAG, "Push message for another phone_id: " + phoneId);
        Logger.W(TAG, "Current phone_id: " + this.getPhoneId().toString());
        return;
    }

    String json = new JSONGenerator(extras).toString();

    Logger.D(TAG, "Received PUSH message: " + json);
    if (callPushCallback(pushType, json)) {
        Logger.T(TAG, "Push message completely handled in callback");
        return;
    }

    final String alert = extras.getString("alert");

    boolean statusNotification = false;
    if (Push.PUSH_NOTIFICATIONS.equals(NOTIFICATION_ALWAYS))
        statusNotification = true;
    else if (Push.PUSH_NOTIFICATIONS.equals(NOTIFICATION_BACKGROUND))
        statusNotification = !RhodesApplication.canHandleNow(RhodesApplication.AppState.AppActivated);

    if (statusNotification) {
        Intent intent = new Intent(getContext(), RhodesActivity.class);
        StatusNotification.simpleNotification(TAG, 0, getContext(), intent, getBuildConfig("name"), alert);
    }

    if (alert != null) {
        Logger.D(TAG, "PUSH: Alert: " + alert);
        Alert.showPopup(alert);
    }
    final String sound = extras.getString("sound");
    if (sound != null) {
        Logger.D(TAG, "PUSH: Sound file name: " + sound);
        Alert.playFile("/public/alerts/" + sound, null);
    }
    String vibrate = extras.getString("vibrate");
    if (vibrate != null) {
        Logger.D(TAG, "PUSH: Vibrate: " + vibrate);
        int duration;
        try {
            duration = Integer.parseInt(vibrate);
        } catch (NumberFormatException e) {
            duration = 5;
        }
        final int arg_duration = duration;
        Logger.D(TAG, "Vibrate " + duration + " seconds");
        Alert.vibrate(arg_duration);
    }

    String syncSources = extras.getString("do_sync");
    if ((syncSources != null) && (syncSources.length() > 0)) {
        Logger.D(TAG, "PUSH: Sync:");
        boolean syncAll = false;
        for (String source : syncSources.split(",")) {
            Logger.D(TAG, "url = " + source);
            if (source.equalsIgnoreCase("all")) {
                syncAll = true;
                break;
            } else {
                final String arg_source = source.trim();
                doSyncSource(arg_source);
            }
        }

        if (syncAll) {
            doSyncAllSources(true);
        }
    }
}