Subby
Subby

Reputation: 5480

Parse.com Send Push Notification With Data

My app uses multiple push notifications. I wish to add some kind of Intent data or any boxed-up data so that when I receive a push notification in my ParsePushBroadcastReceiver, I am able to detect what type of push notification it is and then show the user the appropriate screen. For example, if the notification is telling the user that a friend is trying to add you, it takes the user to the ContractRequest page.

This is what my Receiver currently looks like:

public class ParsePushReceiver extends ParsePushBroadcastReceiver {
    @Override
    public void onPushOpen(final Context context, final Intent intent) {
        Log.i("Push", "Notification Clicked");
        Intent activityIntent = new Intent(context, GameDetailsActivity.class);
        activityIntent.putExtras(intent.getExtras());
        activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(activityIntent);
    }
}

And this is how I typically send a push notification:

ParseQuery query = ParseInstallation.getQuery();
query.whereEqualTo(ParseUserHelper.USERNAME_VAR, contact.getUsername());
ParsePush.sendMessageInBackground(String.format("...");
....

Any ideas how I can wrap data within the notification so that when I intercept it in my receiver, I'll be able to do a switch statement which shall check what type of notification it is and then show the user the correct activity.

Upvotes: 0

Views: 607

Answers (1)

mbm29414
mbm29414

Reputation: 11598

Have a look here at Parse's PUSH Developer Guide.

Specifically of note is this:

It is also possible to specify your own data in this dictionary. As we'll see in the Receiving Notifications section, you're able to use the data sent with your push to do custom processing when a user receives and interacts with a notification.

JSONObject data = new JSONObject("{\"name\": \"Vaughn\",
                               \"newsItem\": \"Man bites dog\"}"));
ParsePush push = new ParsePush();
push.setQuery(injuryReportsQuery);
push.setChannel("Indians");
push.setData(data);
push.sendPushInBackground();

In spite of this sentence:

As we'll see in the Receiving Notifications section, you're able to use the data sent with your push to do custom processing when a user receives and interacts with a notification.

I don't see them giving any details on how to access the data when the PUSH notification is received, but you asked about wrapping the data, not unwrapping it. I would assume that the incoming PUSH notification has a data tag/object/node that contains the JSONObject added on the push side of the PUSH.

Upvotes: 1

Related Questions