Skip to content

How to create android notification channel with custom sound

Alexander Boldyrev edited this page Apr 10, 2025 · 2 revisions

Create a custom notification channel with custom sound for Android

To enable custom sound for notifications, you need to create a custom notification channel. This is done by adding notificationChannelId, notificationChannelName and notificationSound as part of Android configuration in the InfobipMobilemessaging.init method. Note that all three fields must be provided; null or empty strings won't be accepted.

import 'package:infobip_mobilemessaging/models/configurations/configuration.dart' as mmconf;

    InfobipMobilemessaging.init(
      mmconf.Configuration(
        applicationCode: 'APP_CODE',
        androidSettings: mmconf.AndroidSettings(
          notificationChannelId: 'test-channel-id',
          notificationChannelName: 'Test Channel Name',
          notificationSound: 'my_sound',
        ),
      ),
    );

For more about Android notification channels, read Android Developers - Notification Channels

This will create a new custom notification channel with a given notificationChannelId and a notificationChannelName. It will also set the custom sound for notifications. The sound file should be placed in the Android res/raw directory of your project.

Add a sound file to the application project

Place custom sound files in your project in res/raw directory. If the folder does not exist, create it. Make sure that your file is in one of the supported audio formats.

Why don't I hear my custom sound?

MobileMessaging SDK builds a notification in the notification center by using default device sound. Default sound is played if:

  • custom sound name isn't set in the send message API request

Sound will not be played if:

  • sound file name targeted by the API is invalid (valid name: my_sound.wav)
  • sound file is not valid, e.g., the file has a wrong extension

NOTE: Prerequisite for playing any sound is that the sound is enabled for both, a device and your application.

Clone this wiki locally