Global do not disturb
The SDK supports setting a global DND time window and DND level for the current user.
NCEngine.setNoDisturbTime()sets a DND time window starting at an arbitrary time (HH:MM:SS). The window repeats daily until you update or remove it. For example, to set permanent all-day DND, setstartTimeto00:00:00andspanMinutesto1439.- Each user supports only one quiet hours window. Setting a new window replaces the previous one.
During the SDK-configured global quiet hours:
- If the client is offline, the server does not send push notifications.
- Global DND is a user-level setting with the highest priority. When a user has Global DND configured, this setting always takes precedence.
When implementing local notifications in your app, check whether the app has moved to the background. Use the Chat SDK's global DND APIs to decide whether to display a local notification, achieving a global DND effect.
Set quiet hours and DND level
Use the following DND levels when setting quiet hours for the current user:
| Enum value | Value | Description |
|---|---|---|
NoDisturbTimeLevel.DEFAULT | 0 | Not set. The SDK falls back to checking the channel's user-level DND setting and other non-user-level settings. |
NoDisturbTimeLevel.MENTION | 1 | Only notify for @mention messages, including @specific user and @all. For Direct channels, this effectively means no notifications. |
NoDisturbTimeLevel.MUTED | 5 | No notifications at all, even for @mention messages. |
Set quiet hours and level
Use NCEngine.setNoDisturbTime() to set a DND time window with NoDisturbTimeParams. When messages arrive during the quiet hours, the SDK uses the configured level to determine whether to send a push notification.
Parameters (NoDisturbTimeParams)
| Parameter | Type | Description |
|---|---|---|
startTime | String | Start time, down to the second. Format: HH:MM:SS, e.g., 01:31:17. |
spanMinutes | Int | Duration of the DND window in minutes. Range: [1–1439]. Set to 1439 for all-day DND. |
level | NoDisturbTimeLevel | DND level: DEFAULT (0), MENTION (1), or MUTED (5). |
timezone | String | Time zone. Case-sensitive, e.g., "Asia/Shanghai". |
- Kotlin
- Java
val params = NoDisturbTimeParams(
startTime = "00:00:00",
spanMinutes = 1439,
level = NoDisturbTimeLevel.MUTED,
timezone = "Asia/Shanghai"
)
NCEngine.setNoDisturbTime(params) { error ->
if (error == null) {
// Successfully set
} else {
// Failed
}
}
NoDisturbTimeParams params = new NoDisturbTimeParams(
"00:00:00",
1439,
NoDisturbTimeLevel.MUTED,
"Asia/Shanghai"
);
NCEngine.setNoDisturbTime(params, error -> {
if (error == null) {
// Successfully set
} else {
// Failed
}
});
Get quiet hours settings
Use NCEngine.getNoDisturbTime() to retrieve the current global DND settings.
- Kotlin
- Java
NCEngine.getNoDisturbTime { noDisturbTime, error ->
if (error == null && noDisturbTime != null) {
println("Start time: ${noDisturbTime.startTime}")
println("Span minutes: ${noDisturbTime.spanMinutes}")
println("Level: ${noDisturbTime.level}")
} else {
// Failed or not set
}
}
NCEngine.getNoDisturbTime((noDisturbTime, error) -> {
if (error == null && noDisturbTime != null) {
System.out.println("Start time: " + noDisturbTime.getStartTime());
System.out.println("Span minutes: " + noDisturbTime.getSpanMinutes());
System.out.println("Level: " + noDisturbTime.getLevel());
} else {
// Failed or not set
}
});
Multi-device sync
The SDK provides a channel status (pin and DND) sync mechanism. Set a channel status sync listener to receive real-time updates when the channel status changes on another device. See Multi-device channel status sync.