Customizing notifications
Setting up custom push icons
Overview
Android lets you customise the way your notifications look:
Small icon: Required - App icon displayed in your notifications. The small icon must be opaque white, otherwise Android will display a white square.
Accent color: Optional - Color is used by to color your small icon / app name. Android will use a grey accent icolor if you don't set one.
Large icon: Optional - Use it to add contextual information to your message. You shouldn't use it to display your app icon.

Small icon
The small icon allows users to recognize your app when they receive a push. It should be opaque white, using only the alpha channel and 24x24dp. You can easily create one using the Android Assets Studio. \

If you use a colored small icon, Android will display it as a white square: \

Here's how to set it to Batch push:
It can also be configured using a manifest meta-data entry:
Accent color
Google allows you to set an accent color for your push notifications. If you don't set a custom accent color, Android will use a grey accent color.

Here is how to customise that color:
Large icon
The large icon is optional. You can use it to add contextual information to your notification (e.g. an avatar, etc). You shouldn't use the large icon to display the icon of the app. Here is how it looks: \

Here's how to set a custom large icon to Batch push:
Sending silent notifications
Silent push notifications allow you wake up the app to run actions for a limited amount of time without notifying the user.
Here is the key you need to add to your payload to send silent notifications:
Please note that this will work out of the box with Batch’s default receiver. In case you are using a custom receiver, ensure you don’t display any notification when a null value is received for the “msg” parameter.
Setting a custom sound
See our article about notification sounds on Android.
Managing notification display
Using Batch.Push.setShowNotifications, it is possible to toggle whether Batch will show notifications or skips them. This allows you to implement a "Notifications ON/OFF" switch in your app.
Disabling notifications
Enabling notifications
Reading a push's payload from your activity
A push's custom payload can be read from multiple places:
A Notification Interceptor, to be able to enhance the notification using custom payload values
Your own BroadcastReceiver implementation, to be able to act on a push and take full control of what happens when you get one
An Activity, allowing your code to act upon the payload without having to make your own PendingIntent
Most of the time, reading it from the activity is what you're looking for.
If integrated correctly, Batch will attach the full payload to the extras of triggered intent. Depending on your Activity's flags and the current application state, you might get the intent in onCreate() or onNewIntent()
Here's an example of how to read the following custom payload: {"foo": "bar"}
Advanced notification customization
Sometimes, you might want to alter and/or enhance the way Batch builds the notification, or override other fields based on the notification payload. Starting with Batch 1.9.2, Batch includes a notification interception system so you don't have to make your own notification from scratch.
First, you will need to extend the BatchNotificationInterceptor class. It has two methods you can override to tweak notifications:
getPushNotificationCompatBuildergives you full access the theNotificationCompat.Builder. This method is called after Batch is done setting everything up in the builder you get in a parameter. You can add your own customizations to it, or return a totally different builder.getPushNotificationIdlets you change the Notification ID. This is handy to turn the ID into a non unique one, allowing notifications to be updated (such as a sports game score update, for example).
Then you can either use this interceptor in a Batch.Push.displayNotification() call in a custom receiver, or set it globally using Batch.Push.setNotificationInterceptor() in your Application's onCreate().
Example interceptor implementation:
All that is left to do, is to globally register the interceptor:
Adding actions to notifications
By combining Batch Actions and BatchNotificationInterceptor, you can easily add action buttons to notifications based on your custom payload: BatchNotificationAction comes with an helper method allowing you to generate NotificationCompat.Action easily without needing to worry about PendingIntents or services.
Here's an example of BatchNotificationInterceptor implementation that adds a "Call" button for the following custom payload: {"phoneCTA": "123456789"}
Since Android 12 and the new notification trampoline restrictions, your app cannot call startActivity() inside of a service or broadcast receiver. So you have to precise if your action imply showing any UI or will it act in the background by using notificationAction.hasUserInterface = true;
This interceptor assumes that you've registered the CALL action to Batch earlier:
Changing the notification's launch intent
You might also want the notification to launch another intent that the one picked by Batch. Starting with Batch 1.10.2, you can easily generate a valid PendingIntent containing Batch's required extras, or append Batch's data to your own pending intent:
Filtering notifications
A notification interceptor can also be used to filter notifications, by returning null instead of a Builder instance:
This can be used to implement conditional silent notifications, but Batch supports this feature out of the box (click here for more info).
Last updated

