So I need to send a push notification to a user's device. Then when the user clicks on the notification, I need my app to take a specific action. I want to include the parameter for the action in the notification. But I don't want the user to see the parameter; they should just see the message. Doing some research, I found the following on the urban airship website
{
"audience": "all",
"notification": {
"alert": "Extras example",
"android": {
"extra": {
"url": "http://example.com",
"story_id": "1234",
"moar": "{\"key\": \"value\"}"
}
}
},
"device_types": ["android"]
}
So I am supposing that the alert
portion is what a user sees. And that the portion under android
could be the parameters. So my question is, in Java, how do I read those extra portions? such as story_id
, or moar
?
Eran had the right idea, but you actually want to implement PushNotificationBuilder and then override buildNotification().
Something like this:
You can extend
BasicPushNotificationBuilder
and overridebuildNotification
. That method gets the extra parameters inextras
.See docs here.
Since there is no answer accepted here I thought I'll show how I am doing it. I have a class that extends
BroadcastReceiver
like you should if you are following UrbanAirship. In this class I recieve the notifications:Might help someone:)