Skip to main content

Local notifications

Chat UI SDK provides built-in logic to create, display, and handle local notifications.

What are local notifications

Local notifications are created by the SDK or application through the system Notification API when the application process is running.

  • When the application runs in the background and receives a new message, Chat UI triggers a local notification.
  • When the system kills the application, notifications use vendor or system push channels instead of the Chat UI local notification process.
  • When the application is in the foreground but not on a channel screen, the default behavior enables sound and vibration. You can configure silent or notification-only behavior.

Set local notification category

Java
NCChatUIConfig.notificationConfig()
.setCategoryNotification(Notification.CATEGORY_MESSAGE);

Set foreground local notification sound and vibration

Configure through res/values/nc_config.xml:

xml
<!-- Foreground, not on channel screen: enable sound -->
<bool name="nc_sound_in_foreground">true</bool>

<!-- Foreground, not on channel screen: enable vibration -->
<bool name="nc_vibrate_in_foreground">true</bool>

Set dynamically at runtime:

Java
NCChatUIConfig.featureConfig().setVibrateInForeground(true);
NCChatUIConfig.featureConfig().setSoundInForeground(false);

Intercept local notifications

Intercept or modify notification behavior through DefaultInterceptor.

Java
public class MyNotificationInterceptor extends DefaultInterceptor {
@Override
public boolean isNotificationIntercepted(Message message) {
// true: SDK does not display local notification; application handles it
return false;
}

@Override
public boolean isHighPriorityMessage(Message message) {
return false;
}

@Override
public NotificationChannel onRegisterChannel(NotificationChannel defaultChannel) {
return defaultChannel;
}

@Override
public PendingIntent onPendingIntent(PendingIntent pendingIntent, Intent intent) {
// Customize notification click navigation
return pendingIntent;
}
}

NCChatUIConfig.notificationConfig().setInterceptor(new MyNotificationInterceptor());

Chat UI local notification logic

Local notification display depends on:

  • Message notification configuration
  • Global quiet hours
  • Channel-level do-not-disturb level (ChannelNoDisturbLevel)
  • Notification interceptor result

Use these nexconn APIs for custom policies:

kotlin
// Listen for channel status synchronization (pinned, do-not-disturb, etc.)
NCEngine.addChannelHandler(
"notify_channel_status",
object : ChannelHandler {
override fun onChannelNoDisturbLevelSync(event: ChannelNoDisturbLevelSyncEvent) {
// Refresh channel-level do-not-disturb cache
}
}
)

// Query global do-not-disturb configuration
NCEngine.getNoDisturbTime { info, error ->
// info.startTime / info.spanMinutes / info.level
}