Custom sounds
Using custom sounds for your mobile push notification
Android
To use custom push sounds you must add the sound files you wish to play to your project as a resource. Sound files need to be located in the res/raw
directory of the app.
Beginning in Android Oreo, for a notification to use a custom sound it needs to be configured in a notification channel.
To create a notification channel for a sound you would call PushConnector.createNotificationChannel
.
The function takes three parameters: a context, a string for the channel name, and the name of the sound file minus the extension. So for example, if I have a sound file called swish.mp3
in my res/raw
folder, I would create a channel in the following way:
PushConnector.createNotificationChannel(this, "swishChannel", "swish");
You can then use these sounds when creating a push notification campaign on the platform. All that needs to be passed in on the platform side is the name of the file.
The sound field on the platform is included in the the push categories section so in order to be able to use a custom sound when creating a push notification campaign you need to create first a push category. This is where buttons for interactive notifications and other special features of push variants are also setup. See our dedicated guide for detailed instructions on how to do so.
So if I wanted to play a file with the path of res/raw/gong.mp3
you would simply enter the file name under sound as gong.mp3
.
iOS
To use custom push sounds you must add the sound files you wish to play to your project as a non-localized resource of the application bundle as shown below:
<key>UILocalNotificationDefaultSoundName</key>
<string>gong.wav</string>
For more on bundle structure see Apple's Bundle Programming Guide
You can then use these sounds for a push notification. All that needs to be passed in on the platform side is the name of the file.
The sound field on the platform is included in the the push categories section so in order to be able to use a custom sound when creating a push notification campaign you need to create first a push category. This is where buttons for interactive notifications and other special features of push variants are also setup. See our dedicated guide for detailed instructions on how to do so.
Enter the file name under sound. The audio data can be packaged in an AIFF, WAV, or CAF formats. For more info on preparing custom alert sounds see Apple's Local and Remote Push Notification Programming Guide.
Updated almost 3 years ago