How to use Custom Notification Sounds on Android?
On Android 8.0 and higher, notification sounds are managed using Notification Channels. Users can reconfigure those channels. You control the default settings (including the sound and importance), but users can change them at any time. The system always applies the user-defined configuration.
Batch automatically registers a default channel when displaying the first notification if no channel override is set. You cannot change the sound of this channel. You must implement your own channel to define a custom sound.
You must declare your notification channels before sending notifications. Register them during your application’s startup phase. Then, configure Batch to use them by overriding the default channel or by implementing a NotificationChannelIdInterceptor.
Once a channel has been created, you cannot update it. To change the notification sound, you must create a new channel. During development, uninstall and reinstall your application if changes do not apply after updating your code.
Change the Default Sound
To change the default notification sound:
Create your own notification channel and register it with Android.
Implement Multiple Sounds Based on the Notification Payload
To implement multiple notification sounds:
Create multiple notification channels (one per sound).
Implement a
NotificationChannelIdInterceptorand return the appropriate channel based on the custom payload.
Ensure backwards compatibility
Notification channels are not available on versions earlier than Android 8.0. You must implement a NotificationInterceptor to change the notification sound.
Code example
This code implements multiple notification sounds based on the payload content:
A payload of
{ "channel": "win" }playssound_winfrom raw resources.A payload of
{ "channel": "defeat" }playssound_defeatfrom raw resources.Any other value falls back on Batch's default channel.
This snippet works on Android 4.1 and higher. It uses a notification interceptor for devices that do not support channels:
Last updated

