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.

Change the Default Sound

To change the default notification sound:

  1. Create your own notification channel and register it with Android.

Implement Multiple Sounds Based on the Notification Payload

To implement multiple notification sounds:

  1. Create multiple notification channels (one per sound).

  2. Implement a NotificationChannelIdInterceptor and 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" } plays sound_win from raw resources.

  • A payload of { "channel": "defeat" } plays sound_defeat from 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