Push event callback
This reference article covers how to use a callback for Android push events.
Platform availability
This feature is only available for Android—not FireOS.
Using a callback for push events
Braze provides a subscribeToPushNotificationEvents()
callback for when push notifications are received, opened, or dismissed. It is recommended to place this callback in your Application.onCreate()
in order to not miss any events occurring while your application is not running.
If previously using a Custom Broadcast Receiver for this functionality in your application, you can safely remove it in favor of this integration option.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Braze.getInstance(context).subscribeToPushNotificationEvents(event -> {
final BrazeNotificationPayload parsedData = event.getNotificationPayload();
//
// The type of notification itself
//
final boolean isPushOpenEvent = event.getEventType() == BrazePushEventType.NOTIFICATION_OPENED;
final boolean isPushReceivedEvent = event.getEventType() == BrazePushEventType.NOTIFICATION_RECEIVED;
// Sent when a user has dismissed a notification
final boolean isPushDeletedEvent = event.getEventType() == BrazePushEventType.NOTIFICATION_DELETED;
//
// Notification data
//
final String pushTitle = parsedData.getTitleText();
final Long pushArrivalTimeMs = parsedData.getNotificationReceivedTimestampMillis();
final String deeplink = parsedData.getDeeplink();
//
// Custom KVP data
//
final String myCustomKvp1 = parsedData.getBrazeExtras().getString("my first kvp");
final String myCustomKvp2 = parsedData.getBrazeExtras().getString("my second kvp");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Braze.getInstance(context).subscribeToPushNotificationEvents { event ->
val parsedData = event.notificationPayload
//
// The type of notification itself
//
val isPushOpenEvent = event.eventType == BrazePushEventType.NOTIFICATION_OPENED
val isPushReceivedEvent = event.eventType == BrazePushEventType.NOTIFICATION_RECEIVED
// Sent when a user has dismissed a notification
val isPushDeletedEvent = event.eventType == BrazePushEventType.NOTIFICATION_DELETED
//
// Notification data
//
val pushTitle = parsedData.titleText
val pushArrivalTimeMs = parsedData.notificationReceivedTimestampMillis
val deeplink = parsedData.deeplink
//
// Custom KVP data
//
val myCustomKvp1 = parsedData.brazeExtras.getString("my first kvp")
val myCustomKvp2 = parsedData.brazeExtras.getString("my second kvp")
}
With notification action buttons, BRAZE_PUSH_INTENT_NOTIFICATION_OPENED
intents fire when buttons with opens app
or deep link
actions are clicked. Deep link and extras handling remains the same. Buttons with close
actions don’t fire BRAZE_PUSH_INTENT_NOTIFICATION_OPENED
intents and dismiss the notification automatically.
Create your push notification listener in Application.onCreate
to ensure your listener is triggered after an end-user taps a notification while your app is in a terminated state.