Example usage for android.os Bundle containsKey

List of usage examples for android.os Bundle containsKey

Introduction

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

Prototype

public boolean containsKey(String key) 

Source Link

Document

Returns true if the given key is contained in the mapping of this Bundle.

Usage

From source file:com.onesignal.NotificationBundleProcessor.java

private static void prepareBundle(Bundle gcmBundle) {
    if (gcmBundle.containsKey("o")) {
        try {/*w  ww .  ja  va2  s  . co  m*/
            JSONObject customJSON = new JSONObject(gcmBundle.getString("custom"));
            JSONObject additionalDataJSON;

            if (customJSON.has("a"))
                additionalDataJSON = customJSON.getJSONObject("a");
            else
                additionalDataJSON = new JSONObject();

            JSONArray buttons = new JSONArray(gcmBundle.getString("o"));
            gcmBundle.remove("o");
            for (int i = 0; i < buttons.length(); i++) {
                JSONObject button = buttons.getJSONObject(i);

                String buttonText = button.getString("n");
                button.remove("n");
                String buttonId;
                if (button.has("i")) {
                    buttonId = button.getString("i");
                    button.remove("i");
                } else
                    buttonId = buttonText;

                button.put("id", buttonId);
                button.put("text", buttonText);

                if (button.has("p")) {
                    button.put("icon", button.getString("p"));
                    button.remove("p");
                }
            }

            additionalDataJSON.put("actionButtons", buttons);
            additionalDataJSON.put("actionSelected", DEFAULT_ACTION);
            if (!customJSON.has("a"))
                customJSON.put("a", additionalDataJSON);

            gcmBundle.putString("custom", customJSON.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static String getAppMetadata(Context context, String key) {
    String strValue = "";
    try {//www . j  a v a  2 s  .  com
        PackageManager mgr = context.getPackageManager();
        Bundle bundle = mgr.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA).metaData;
        //Bundle bundle = context.getApplicationInfo().metaData;
        if (bundle != null && bundle.containsKey(key)) {
            strValue = bundle.getString(key);
        }
    } catch (Exception e) {
        Log.w(LOG_TAG, e);
    }

    return strValue;
}

From source file:org.linkdroid.PostJob.java

private static boolean shouldDoHmac(Bundle webhook) {
    return webhook.containsKey(WebhookColumns.SECRET)
            && !TextUtils.isEmpty(webhook.getString(WebhookColumns.SECRET));
}

From source file:com.facebook.TestUtils.java

public static void assertEqualContents(final Bundle a, final Bundle b) {
    for (String key : a.keySet()) {
        if (!b.containsKey(key)) {
            Assert.fail("bundle does not include key " + key);
        }//from w w  w  .  java2 s .c om
        Assert.assertEquals(a.get(key), b.get(key));
    }
    for (String key : b.keySet()) {
        if (!a.containsKey(key)) {
            Assert.fail("bundle does not include key " + key);
        }
    }
}

From source file:Main.java

/**
 * Store the exif attributes in the passed image file using the TAGS stored in the passed bundle
 *
 * @param filepath//from  w  w w.j  a va2 s . c  o m
 * @param bundle
 * @return true if success
 */
public static boolean saveAttributes(final String filepath, Bundle bundle) {
    ExifInterface exif;
    try {
        exif = new ExifInterface(filepath);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    for (String tag : EXIF_TAGS) {
        if (bundle.containsKey(tag)) {
            exif.setAttribute(tag, bundle.getString(tag));
        }
    }
    try {
        exif.saveAttributes();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.nextgis.maplibui.util.ControlHelper.java

public static boolean hasKey(Bundle savedState, String fieldName) {
    return savedState != null && savedState.containsKey(getSavedStateKey(fieldName));
}

From source file:ru.appsm.inapphelp.IAHHelpDesk.java

/**
 *
 * Handle push notification.//from   ww w. j  a  va2s.c  o  m
 *
 * @param intent
 * @param context
 */
public static void HandelPushIntentWithContext(Intent intent, Context context) {
    Log.i(TAG, "handle push");
    Bundle extras = intent.getExtras();
    if (extras != null && extras.containsKey("secretkey") && extras.containsKey("userid")
            && extras.containsKey("appkey") && extras.containsKey("appid") && extras.containsKey("email")
            && extras.containsKey("message") && extras.containsKey("title") && extras.containsKey("notId")
            && extras.containsKey("msgId")) {
        JSONObject data = new JSONObject();
        int notId = 1;
        try {
            notId = Integer.parseInt(extras.getString("notId"));
        } catch (NumberFormatException e) {
            notId = 1;
        }
        try {
            data.put("notId", notId);
            data.put("userid", extras.getString("userid"));
            data.put("appid", extras.getString("appid"));
            data.put("appkey", extras.getString("appkey"));
            data.put("secretkey", extras.getString("secretkey"));
            data.put("email", extras.getString("email"));
            data.put("title", extras.getString("title"));
            data.put("message", extras.getString("message"));
            data.put("msgId", extras.getString("msgId"));
            data.put("sound", extras.getString("sound"));
            IAHHelpDesk.BuildNotificationForDataWithContext(data, context);
        } catch (JSONException e) {
            Log.i(TAG, "Fail to parse push data");
        }
    } else {
        Log.i(TAG, "Empty or wrong push intent");
    }
}

From source file:com.arellomobile.android.push.PushGCMIntentService.java

private static void generateBroadcast(Context context, Bundle extras) {
    Intent broadcastIntent = new Intent();
    broadcastIntent.setAction(context.getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");
    broadcastIntent.putExtras(extras);/*from  w  ww .  java 2  s. c  om*/

    JSONObject dataObject = new JSONObject();
    try {
        if (extras.containsKey("title")) {
            dataObject.put("title", extras.get("title"));
        }
        if (extras.containsKey("u")) {
            dataObject.put("userdata", new JSONObject(extras.getString("u")));
        }
    } catch (JSONException e) {
        // pass
    }

    broadcastIntent.putExtra(BasePushMessageReceiver.DATA_KEY, dataObject.toString());

    context.sendBroadcast(broadcastIntent, context.getPackageName() + ".permission.C2D_MESSAGE");
}

From source file:com.facebook.notifications.NotificationsManager.java

/**
 * Returns whether or not a notification bundle has a valid push payload.
 *
 * @param notificationBundle The bundle to check for a push payload
 *///from ww w. java  2 s  . co m
public static boolean canPresentCard(@NonNull Bundle notificationBundle) {
    return notificationBundle.containsKey(CARD_PAYLOAD_KEY);
}

From source file:edu.stanford.junction.android.AndroidJunctionMaker.java

public static Junction newJunction(Intent intent, JunctionActor actor) throws JunctionException {
    Bundle bundle = intent.getExtras();
    if (bundle == null || !bundle.containsKey(Intents.EXTRA_ACTIVITY_SESSION_URI)) {
        throw new JunctionException("No session uri found.");
    }/*from  w ww. jav  a2  s .  com*/

    URI uri = URI.create(bundle.getString(Intents.EXTRA_ACTIVITY_SESSION_URI));
    SwitchboardConfig cfg = AndroidJunctionMaker.getDefaultSwitchboardConfig(uri);
    AndroidJunctionMaker maker = AndroidJunctionMaker.getInstance(cfg);

    ActivityScript script = null;
    if (bundle.containsKey(Intents.EXTRA_ACTIVITY_SCRIPT)) {
        try {
            JSONObject json = new JSONObject(bundle.getString(Intents.EXTRA_ACTIVITY_SCRIPT));
            script = new ActivityScript(json);
        } catch (JSONException e) {
            throw new JunctionException("Bad activity script in Intent.", e);
        }
    }

    return maker.newJunction(uri, script, actor);
}