Implement Default and Custom Notification Channels

On devices that run Android 8.0 or later, the SDK creates a default notification channel called marketing to assign all notifications to it. To change the name of the default channel, set a string resource value for mcsdk_default_notification_channel_name.

After the SDK creates the NotificationChannel, the channel isn’t updated unless your application calls NotificationManager#createDefaultNotificationChannel(Context context, boolean forceRecreate).

Custom Configuration 

You can create custom notification channels and assign channels to each notification, as depicted by the following example configuration.

1val channelId = "my_custom_channel"
2
3if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
4  (getSystemService(Context.NOTIFICATION_SERVICE) as android.app.NotificationManager).createNotificationChannel(
5    NotificationChannel(
6      channelId,
7      "Marketing Messages",
8      android.app.NotificationManager.IMPORTANCE_DEFAULT
9    )
10  )
11}
12
13SFMCSdk.configure(applicationContext as Application, SFMCSdkModuleConfig.build {
14   pushFeatureModuleConfig = PushFeatureConfig.builder().apply {
15    // Other configuration options
16    setNotificationCustomizationOptions(
17      NotificationCustomizationOptions.create(
18        R.drawable.ic_notification_icon,
19        null,
20        NotificationManager.NotificationChannelIdProvider { context, notificationMessage ->
21          // Custom logic to determine which channel to use for the message.
22          channelId
23        }
24      )
25    )
26  }.build()
27}) {
28  // TODO handle initialization status
29}

To assign a notification to a channel, implement the SDK NotificationChannelIdProvider interface. Ensure that you include a channel with your message. Otherwise, the app doesn’t display the message to the recipient.

You can customize channel priority, colors, and sounds. To use custom sounds, give each channel its own sound configuration while creating it. You can’t use sounds with the SDK default channel option.

Note