Skip to content

Custom message payload

Tereza Juric edited this page Aug 8, 2017 · 22 revisions

By using Custom Payload you can send custom data together with regular push messages from New Campaign page on Customer portal. The custom payload can be made of key-value pairs:

CUP Settings

or plain JSON:

CUP Settings

It is also possible to send Custom Payload using Single PUSH message and Multiple PUSH messages APIs.

The following example code shows how you can retrieve the custom payload bundle from within your application by subscribing to message received Event:

// declare message receiver
private final BroadcastReceiver messageReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        Message message = Message.createFrom(intent.getExtras());

        // extract your custom data
        JSONObject customPayload = message.getCustomPayload();
        if (customPayload != null) {
            final String uri = customPayload.optString("uri", "");
            final String dish = customPayload.optString("dish", "");

            Log.d("CustomPayload", String.format("dish is: %s, uri is: %s", uri, dish));
        }
    }
}

@Override
protected void onResume() {
    super.onResume();
    // subscribe to MESSAGE_RECEIVED event
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
    localBroadcastManager.registerReceiver(messageReceiver, new IntentFilter(Event.MESSAGE_RECEIVED.getKey()));
}
Clone this wiki locally