Global Do Not Disturb
The SDK supports setting global Do Not Disturb time windows and levels for the current user.
- The [setNotificationQuietHoursLevel] interface sets a Do Not Disturb time window starting from any specified time (
HH:MM:SS). The configured time window will repeat daily until the user modifies or removes the setting. For example, to enable permanent all-day Do Not Disturb, setstartTimeto00:00:00andperiodto1439. - Each user can only configure one time window - new settings will overwrite previous configurations.
- For SDK versions < 5.2.2, only time window configuration is supported without level settings. We recommend upgrading to the latest stable or development version.
During globally configured Do Not Disturb periods:
- When the client is offline, RC server will not send push notifications.
- Global Do Not Disturb periods are user-level settings with the highest priority. When configured, these settings override all other Do Not Disturb configurations.
For apps implementing custom local notifications, when detecting the app has moved to background, you can use the global Do Not Disturb interface from IMLib SDK to determine whether to display local notifications, achieving global Do Not Disturb effects.
Configure Do Not Disturb Period and Level (SDK ≥ 5.2.2)
Starting from SDK 5.2.2, the following Do Not Disturb levels are available when configuring time windows:
Parameter Description
| Enum Value | Code | Description |
|---|---|---|
| PUSH_NOTIFICATION_QUIET_HOURS_LEVEL_DEFAULT | 0 | Not set. When unset, SDK checks group-level and other non-user-level settings to determine notification needs. |
| PUSH_NOTIFICATION_QUIET_HOURS_LEVEL_MENTION_MESSAGE | 1 | Only notifies for @mentions, including @user and @all messages. For one-to-one chats, no notifications sent. |
| PUSH_NOTIFICATION_QUIET_HOURS_LEVEL_BLOCKED | 5 | Blocks all notifications, including @mention messages. |
Configure Do Not Disturb Period and Level
This interface is available in [ChannelClient] starting from version 5.2.2.
Configures message notification quiet hours. During these periods, notification delivery follows the configured Do Not Disturb level.
Interface
ChannelClient.getInstance().setNotificationQuietHoursLevel(startTime, spanMinutes,callback);
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| startTime | String | Start time in HH:MM:SS format (e.g. 01:31:17), precise to seconds. |
| spanMinutes | int | Do Not Disturb window duration in minutes. Range: [1-1439]. |
| lev | PushNotificationQuietHoursLevel |
|
| callback | ResultCallback<List<Conversation>> | Callback interface |
Sample Code
String startTime = "00:00:00";
int spanMinutes = 1439;
ChannelClient.getInstance().setNotificationQuietHoursLevel(startTime, spanMinutes,
IRongCoreEnum.PushNotificationQuietHoursLevel.PUSH_NOTIFICATION_QUIET_HOURS_LEVEL_DEFAULT,
new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {
}
});
Configure Do Not Disturb Period and Level (Timezone Support)
[ChannelClient] interface available starting from version 5.14.0.
Configures message notification quiet hours through NotificationQuietHoursSetting with timezone support. During these periods, notification delivery follows the configured Do Not Disturb level.
Interface
ChannelClient.getInstance().setNotificationQuietHoursLevel(setting, callback);
NotificationQuietHoursSetting Parameter Introduction
| Parameter | Type | Description |
|---|---|---|
| startTime | String | Start time, accurate to seconds. Format: HH:MM:SS, e.g. 01:31:17. |
| spanMinutes | int | Do Not Disturb time window duration in minutes. Range: [1-1439]. |
| level | PushNotificationQuietHoursLevel |
|
| timeZone | String | Defaults to Asia/Shanghai for China (Beijing) Data Center, UTC for global data centers. |
Sample Code
NotificationQuietHoursSetting setting = new NotificationQuietHoursSetting();
setting.setStartTime("00:00:00");
setting.setSpanMinutes(1439);
setting.setTimeZone("Asia/Shanghai");
setting.setLevel(IRongCoreEnum.PushNotificationQuietHoursLevel.PUSH_NOTIFICATION_QUIET_HOURS_LEVEL_DEFAULT);
ChannelClient.getInstance().setNotificationQuietHoursLevel(setting, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {
}
});
### Remove Do Not Disturb Period and Level
:::tip
This interface is supported in [ChannelClient] starting from version 5.2.2.
:::
You can call the following method to remove the Do Not Disturb time period settings.
#### Interface
```java
ChannelClient.getInstance().removeNotificationQuietHours(callback);
### Get Do Not Disturb Period and Level
:::tip
This interface is supported in [ChannelClient] starting from version 5.2.2.
:::
You can use the following method to retrieve the Do Not Disturb time period settings. When messages are received during the Do Not Disturb period, the system will determine whether to push notifications based on the current Do Not Disturb level.
#### Interface
```java
ChannelClient.getInstance().getNotificationQuietHoursLevel(callback);
#### Parameter Description
| Parameter | Type | Description |
|:--------------|:--------------------------------------|:-----------------------------------------------------------------------|
| callback | [GetNotificationQuietHoursCallbackEx] | Callback for retrieving Do Not Disturb settings. Returns `startTime`, `spanMinutes`, and `level` on success. |
[GetNotificationQuietHoursCallbackEx]: https://doc.rongcloud.cn/apidoc/imlibcore-android/latest/zh_CN/html/-android--i-m-lib-core--s-d-k/io.rong.imlib/-i-rong-core-callback/-get-notification-quiet-hours-callback-ex/index.html
### Get Do Not Disturb Period and Level (with Timezone Support)
:::tip
[ChannelClient] interface is supported starting from version 5.14.0.
:::
You can use the following method to retrieve the Do Not Disturb time period settings, where `NotificationQuietHoursSetting` includes the timezone. When messages are received during the Do Not Disturb period, the system will determine whether to push notifications based on the current Do Not Disturb level.
#### Interface
```java
ChannelClient.getInstance().getNotificationQuietHoursLevel(callback);
#### Parameter Description
| Parameter | Type | Description |
|:--------------|:----------------------------------|:-----------------------------------------------------------------------|
| callback | [ResultCallback] | Callback for retrieving Do Not Disturb settings. Returns `startTime`, `spanMinutes`, `level`, and `timeZone` on success. |
[setNotificationQuietHoursLevel]:https://doc.rongcloud.cn/apidoc/imlibcore-android/latest/zh_CN/html/-android--i-m-lib-core--s-d-k/io.rong.imlib/-channel-client/set-notification-quiet-hours-level.html?query=public%20abstract%20void%C2%A0setNotificationQuietHoursLevel(NotificationQuietHoursSetting%C2%A0setting,%20IRongCoreCallback.OperationCallback%C2%A0callback)
[ChannelClient]: https://doc.rongcloud.cn/apidoc/imlibcore-android/latest/zh_CN/html/-android--i-m-lib-core--s-d-k/io.rong.imlib/-channel-client/index.html