Custom Alert Sounds

Play a custom alert sound when the user receives a push

Custom sounds can be a great way to make your application stand out. When you don't customise sounds, your app uses the system setting for receiving an SMS. In some cases, this may cause the user to either disable sound, disable push or uninstall your application. Having a unique and entertaining sound appropriate for your context is a great way to keep users engaged. This article will help you implement custom sounds on iOS and Android with Marigold.

On iOS

Default sound

For a default sound, use the key default in the Marigold dashboard or via the API as the sound key.

Vibration

Whether the sound plays or a vibration occurs is a device level setting controlled by the user. This is set in the user's settings. You cannot specify that a vibration should occur with a special push payload. If you want a vibrate you occur every time, the suggested technique is to programmatically vibrate the phone when a push arrives, but this is still subject to user settings.

Custom Sounds

For iOS, you need to include the right type of file in your app bundle, which Preparing Custom Alert Sounds covers in detail. If the audio file doesn’t exist or default is specified as the value, the default alert sound is played. The audio must be in one of the audio data formats that are compatible with system sounds.

On Android

Like on iOS, Android uses a packaged sound for custom sounds. You should simply put the audio file under res/raw folder of your project. If the sound can't be found, the default will be played.

📘

See Supported Media Formats on the Android docs for details on what audio file formats are supported on Android devices.

📘

Note

As of Android Oreo (8), the notification sound is set as part of the notification channel and cannot be overridden using the push payload. Please Customise your notification channels to set a custom sound, but be aware that the user can adjust the sound in the app settings.

Publishing

When it comes time to publish your message, simply enter the file name in the message compose screen. For example, if you're sending a photo of a cat in an image type message, you might want to send a custom sound that sounds like a cat purring.

🚧

On Android, the filename entered in the sound field must not contain the file extension.

Optimizing for both platforms

A common file type between both Android and iOS is a linear PCM Wave file with a .wav extension. You can then generate the audio file once from your audio software and use for both applications.