How Do I Send Extra Data Through An Urbanairship Push Notification
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 fo
Solution 1:
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:
publicclassIntentReceiverextendsBroadcastReceiver {
privatestaticfinalStringlogTag="PushUA";
private String pushToken;
publicstaticStringAPID_UPDATED_ACTION_SUFFIX=".apid.updated";
@OverridepublicvoidonReceive(Context context, Intent intent) {
Log.i(logTag, "Received intent: " + intent.toString());
Stringaction= intent.getAction();
if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) {
intid= intent.getIntExtra(PushManager.EXTRA_NOTIFICATION_ID, 0);
logPushExtras(intent);
} elseif (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) {
Log.i(logTag, "User clicked notification. Message: " + intent.getStringExtra(PushManager.EXTRA_ALERT));
logPushExtras(intent);
String url= intent.getStringExtra("url"); //Here you get your extras
...
Might help someone:)
Solution 2:
You can extend BasicPushNotificationBuilder
and override buildNotification
. That method gets the extra parameters in extras
.
@OverridepublicNotificationbuildNotification(String alert, Map<String, String> extras) {
// Only build inbox style notification for rich push messagesif (extras != null && RichPushManager.isRichPushMessage(extras)) {
returncreateRichNotification(alert);
} else {
returnsuper.buildNotification(alert, extras);
}
}
See docs here.
Solution 3:
Eran had the right idea, but you actually want to implement PushNotificationBuilder and then override buildNotification().
Something like this:
/**
* This class encapsulates notifications (those that appear in the notification shade).
*
* @author Karim Varela
*/publicclassManagerNotificationsimplementsPushNotificationBuilder
{
@OverridepublicNotificationbuildNotification(String alert, Map<String, String> extras)
{
returnnull;
}
@Overridepublic int getNextId(String alert, Map<String, String> extras)
{
return0;
}
}
Post a Comment for "How Do I Send Extra Data Through An Urbanairship Push Notification"