NotificationChannelIdProvider
Provide a NotificationChannelIdProvider in NotificationCustomizationOptions to assign a android.app.NotificationChannel per NotificationMessage.
On Android 8 (API 26) and higher the channel's android.app.NotificationChannel.lockscreenVisibility is the ceiling for lock-screen content. A notification can only be made more hidden than its channel, never more visible. The SDK default channel is Notification.VISIBILITY_PRIVATE, so a server-set NotificationMessage.Visibility.PUBLIC value is a no-op unless the app routes that message to a channel created with Notification.VISIBILITY_PUBLIC. Channel visibility cannot be changed after the channel is created — use a new channel id; do not recreate the SDK default.
val PUBLIC_CHANNEL_ID = "com.example.push.PUBLIC"
fun createPublicChannel(context: Context) {
val androidNotificationManager =
context.getSystemService(android.app.NotificationManager::class.java) ?: return
if (androidNotificationManager.getNotificationChannel(PUBLIC_CHANNEL_ID) == null) {
NotificationChannel(
PUBLIC_CHANNEL_ID,
"Public lock-screen",
android.app.NotificationManager.IMPORTANCE_DEFAULT
).apply {
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
androidNotificationManager.createNotificationChannel(this)
}
}
}
val channelIdProvider = NotificationChannelIdProvider { context, message ->
if (message.visibility == NotificationMessage.Visibility.PUBLIC) {
PUBLIC_CHANNEL_ID
} else {
val payloadChannelId = message.channelId
if (payloadChannelId != null) {
try {
val manager = context.getSystemService(android.app.NotificationManager::class.java)
if (manager?.getNotificationChannel(payloadChannelId) != null) {
payloadChannelId
} else {
NotificationManager.DEFAULT_CHANNEL_ID
}
} catch (e: Exception) {
NotificationManager.DEFAULT_CHANNEL_ID
}
} else {
NotificationManager.DEFAULT_CHANNEL_ID
}
}
}
NotificationCustomizationOptions.create(
R.drawable.ic_notification,
launchIntentProvider,
channelIdProvider
)Without a NotificationChannelIdProvider, the SDK looks up NotificationMessage.channelId with android.app.NotificationManager.getNotificationChannel and uses that ID when the channel already exists. Missing channels and lookup failures fall back to the SDK default channel. The SDK never creates a payload-requested channel.
When a NotificationChannelIdProvider is supplied, automatic payload lookup is disabled and the provider owns channel selection. The returned ID is used as-is without SDK validation. If the provider throws, or a Java implementation returns null despite the non-null contract, the SDK falls back to its default channel without attempting automatic payload-channel lookup.