设置会话免打扰
IMKit SDK 支持基于会话类型或会话 ID 设置免打扰,后台运行时仅静默接收消息内容,离线状态下则不会触发厂商推送提醒。
免打扰状态实时同步至服务端,并由融云实现跨设备自动同步,客户端可监听状态变更或主动查询最新数据。
设置会话的免打扰状态
IMCenter 的 setConversationNotificationStatus 方法,支持按会话类型或 ID 设置免打扰状态,生效后将屏蔽后台及离线状态下的消息通知,并在会话列表中以灰色铃铛图标标识。
接口
Java
IMCenter.getInstance().setConversationNotificationStatus(conversationType, targetId, notificationStatus, callback);
参数说明
| 参数 | 类型 | 说明 |
|---|---|---|
| conversationType | ConversationType | 会话类型。不支持聊天室类型,因为聊天室默认不支持消息提醒。 |
| targetId | String | 会话 Id |
| notificationStatus | ConversationNotificationStatus | 消息状态设置。DO_NOT_DISTURB 为免打扰状态。NOTIFY 为提醒状态。 |
| callback | ResultCallback<ConversationNotificationStatus> | 回调接口 |
示例代码
Java
ConversationType conversationType = ConversationType.PRIVATE;
String targetId = " 会话 Id ";
// 消息免打扰
ConversationNotificationStatus notificationStatus = ConversationNotificationStatus.DO_NOT_DISTURB;
IMCenter.getInstance().setConversationNotificationStatus(conversationType, targetId, notificationStatus, new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {
@Override
public void onSuccess(Conversation.ConversationNotificationStatus status) {
}
@Override
public void onError(RongIMClient.ErrorCode errorCode) {
}
});