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.
You can create custom notification channels and assign channels to each notification, as depicted by the following example configuration.
1val channelId = "my_custom_channel"23if(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_DEFAULT9)10)11}1213SFMCSdk.configure(applicationContext as Application, SFMCSdkModuleConfig.build{14 pushFeatureModuleConfig = PushFeatureConfig.builder().apply{15 // Other configuration options16 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 channelId23}24)25)26}.build()27}){28 // TODO handle initialization status29}
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.