-
Notifications
You must be signed in to change notification settings - Fork 11
How to create android notification channel with custom sound
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.
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.
In order for custom notification sound to be played by the OS, you need to send message by API with the name of the sound (with or without extension) by using soundName
parameter in options
, or Portal by filling Sound name
field in Advanced Settings -> Notification Settings -> Standard -> Play Sound on Device .
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
Sound will not be played if:
- sound file is not found by the provided name (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.
- Library events
- Server errors
- Users and installations
- Messages and notifications management
- Inbox
- Privacy settings
- In-app chat
- WebRTC Calls and UI
- Migration Guides
- JSON Web Token (JWT) structure and generation example