系统设置

更新时间: 2025/07/16 14:15:25

网易云信即时通讯 SDK(NetEase IM SDK,以下简称 NIM SDK)提供系统设置相关功能,支持设置单聊/群聊消息免打扰、获取会话消息的免打扰状态等。

本文介绍系统设置相关 API。

API 概览

系统设置监听

API 说明 起始版本
listen 注册系统设置相关监听器 v10.3.0
cancel 取消注册系统设置相关监听器 v10.3.0

系统设置操作

API 说明 起始版本
setP2PMessageMuteMode 设置单聊消息免打扰模式 v10.3.0
getP2PMessageMuteMode 获取单聊消息免打扰模式 v10.3.0
getP2PMessageMuteList 获取开启单聊消息免打扰的用户列表 v10.3.0
setTeamMessageMuteMode 设置群消息免打扰模式 v10.3.0
getTeamMessageMuteMode 获取群消息免打扰模式 v10.3.0
getConversationMuteStatus 获取会话消息免打扰状态 v10.3.0
setPushMobileOnDesktopOnline 设置当桌面端在线时,移动端是否需要推送 v10.3.0
setDndConfig 设置推送全局免打扰 v10.3.0
getDndConfig 获取推送免打扰配置信息 v10.3.0
updateNotificationConfigAndroid 更新通知栏设置,仅支持 Android 平台 v10.5.0
enableNotificationAndroid 配置消息提醒,仅支持 Android 平台iOS 平台请关闭通知权限。 v10.5.0
getPushMobileOnDesktopOnline 获取当桌面端在线时,移动端是否需要推送 v10.9.0

接口类

SettingsService 类提供系统设置相关接口,包括设置单聊/群聊消息免打扰模式、获取单聊/群聊消息免打扰模式、获取单聊消息免打扰列表、获取会话消息的免打扰状态等接口。

listen

接口描述

注册系统设置相关监听。

注册成功后,当事件发生时,SDK 会返回对应的回调。

  • 建议在初始化后调用该方法。
  • 全局只需注册一次。
  • 该方法为同步。

回调事件

  • onTeamMessageMuteModeChanged:群消息免打扰模式变更回调,包括群组 ID、群组类型、群消息免打扰模式。
  • onP2PMessageMuteModeChanged:单聊(点对点)消息免打扰模式变更回调,包括聊天对象账号、单聊消息免打扰模式。
  • onPushMobileOnDesktopOnline:当桌面端在线时,移动端是否需要推送的在线通知回调。

示例代码

dartsubsriptions.add(NimCore.instance.settingsService.onP2PMessageMuteModeChanged.listen((e) {
    // do something
  }));

subsriptions.add(NimCore.instance.settingsService.onTeamMessageMuteModeChanged.listen((e) {
  // do something
}));

subsriptions.add(NimCore.instance.settingsService.onPushMobileOnDesktopOnline.listen((e) {
  // do something
}));

cancel

接口描述

取消注册系统设置相关监听。

该方法为同步。

示例代码

dartsubsriptions.forEach((subsription) {
    subsription.cancel();
  });

setP2PMessageMuteMode

接口描述

设置单聊(点对点)消息免打扰模式。

本地端或多端同步设置成功后,SDK 会返回单聊消息免打扰模式变更回调 onP2PMessageMuteModeChanged,并触发会话变更。

参数说明

dartFuture<NIMResult<void>> setP2PMessageMuteMode(
    String accountId, NIMP2PMessageMuteMode muteMode) async {
  return _platform.setP2PMessageMuteMode(accountId, muteMode);
}
参数名称 类型 是否必填 说明
accountId String 聊天对象用户账号,不可为空,否则返回 191004 参数错误。
muteMode NIMP2PMessageMuteMode 消息免打扰模式:免打扰开启或免打扰关闭。

示例代码

dartawait NimCore.instance.settingsService.setP2PMessageMuteMode(accountId, muteMode);

返回值

NIMResult<void>

相关回调

onP2PMessageMuteModeChanged:单聊消息免打扰模式变更回调

getP2PMessageMuteMode

接口描述

获取单聊(点对点)消息免打扰模式。

参数说明

dartFuture<NIMResult<NIMP2PMessageMuteMode>> getP2PMessageMuteMode(
    String accountId) async {
  return _platform.getP2PMessageMuteMode(accountId);
}
参数名称 类型 是否必填 说明
accountId String 聊天对象用户账号,如果为空、不合法、不存在,则返回 191004 参数错误。

示例代码

dartawait NimCore.instance.settingsService.getP2PMessageMuteMode(accountId);

返回值

NIMResult<NIMP2PMessageMuteMode>:单聊(点对点)消息免打扰模式

相关回调

getP2PMessageMuteList

接口描述

获取开启单聊(点对点)消息免打扰的用户列表。

参数说明

dartFuture<NIMResult<List<String>>> getP2PMessageMuteList() async {
  return _platform.getP2PMessageMuteList();
}

示例代码

dartawait NimCore.instance.settingsService.getP2PMessageMuteList();

返回值

NIMResult<List<String>>:开启单聊消息免打扰的用户列表

相关回调

setTeamMessageMuteMode

接口描述

设置群聊消息免打扰模式。

本地端或多端同步设置成功后,SDK 会返回群聊消息免打扰模式变更回调 onTeamMessageMuteModeChanged,并触发会话变更。

参数说明

dartFuture<NIMResult<void>> setTeamMessageMuteMode(String teamId,
    NIMTeamType teamType, NIMTeamMessageMuteMode muteMode) async {
  return _platform.setTeamMessageMuteMode(teamId, teamType, muteMode);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。
muteMode NIMTeamMessageMuteMode 群消息免打扰模式:免打扰开启或免打扰关闭。

示例代码

dartawait NimCore.instance.settingsService.setTeamMessageMuteMode(teamId, teamType, muteMode);

返回值

NIMResult<void>

相关回调

onTeamMessageMuteModeChanged:群聊消息免打扰模式变更回调

getTeamMessageMuteMode

接口描述

获取群聊消息免打扰模式。

参数说明

dartFuture<NIMResult<NIMTeamMessageMuteMode?>> getTeamMessageMuteMode(
    String teamId, NIMTeamType teamType) async {
  return _platform.getTeamMessageMuteMode(teamId, teamType);
}
参数名称 类型 是否必填 说明
teamId String 群组 ID。如果为空、不合法、不存在则返回 191004 参数错误。
teamType NIMTeamType 群组类型,包括高级群和超大群。

示例代码

dartawait NimCore.instance.settingsService.getTeamMessageMuteMode(teamId, teamType);

返回值

NIMResult<NIMTeamMessageMuteMode?>:群聊消息免打扰模式

相关回调

getConversationMuteStatus

接口描述

获取会话消息免打扰状态。

如果该方法返回值不满足界面显示需求,可以调用 getP2PMessageMuteModegetTeamMessageMuteMode 方法获取单聊或群聊消息的具体免打扰模式。

参数说明

dartFuture<NIMResult<bool>> getConversationMuteStatus(
    String conversationId) async {
  return _platform.getConversationMuteStatus(conversationId);
}
参数名称 类型 是否必填 说明
conversationId String 会话 ID,通过调用 ConversationIdUtil 的对应函数创建。
  • 组成方式:用户账号(accountId)| 会话类型(NIMConversationType)| 聊天对象账号(accountId)或群组 ID。
  • 不可设置为空,否则返回 191004 参数错误。
  • 示例代码

    dartawait NimCore.instance.settingsService.getConversationMuteStatus(conversationId);
    

    返回值

    NIMResult<bool>

    • true:会话消息免打扰开启。
    • false:会话消息免打扰关闭。

    相关回调

    setPushMobileOnDesktopOnline

    接口描述

    设置当桌面端在线时,移动端是否需要推送。

    参数说明

    dartFuture<NIMResult<void>> setPushMobileOnDesktopOnline(bool need) async {
      return _platform.setPushMobileOnDesktopOnline(need);
    }
    
    参数名称 类型 是否必填 说明
    need bool 桌面端在线时,移动端是否需要推送,默认为 true。
  • true:需要
  • false:不需要
  • 示例代码

    dartawait NimCore.instance.settingsService.setPushMobileOnDesktopOnline(need);
    

    返回值

    NIMResult<void>

    相关回调

    setDndConfig

    接口描述

    设置推送全局免打扰。

    参数说明

    dartFuture<NIMResult<void>> setDndConfig(NIMDndConfig config) async {
      return _platform.setDndConfig(config);
    }
    
    参数名称 类型 是否必填 说明
    config NIMDndConfig 推送全局免打扰配置信息。

    示例代码

    dartawait NimCore.instance.settingsService.setDndConfig(config);
    

    返回值

    NIMResult<void>

    相关回调

    getDndConfig

    接口描述

    获取推送全局免打扰配置详情。

    参数说明

    dartFuture<NIMResult<NIMDndConfig>> getDndConfig() async {
      return _platform.getDndConfig();
    }
    

    示例代码

    dartawait NimCore.instance.settingsService.getDndConfig();
    

    返回值

    NIMResult<NIMDndConfig>:推送全局免打扰配置信息

    enableNotificationAndroid

    接口描述

    配置消息提醒,仅支持 Android 平台。

    可以通过本接口开启消息提醒功能和消息撤回提醒功能。调用该方法成功后,还需要调用 updateNotificationConfigAndroid 方法更新配置,更新成功后,设置的消息提醒才会生效。

    iOS 平台请关闭通知权限。

    参数说明

    dartFuture<NIMResult<void>> enableNotificationAndroid({required bool enableRegularNotification,required bool enableRevokeMessageNotification})
    
    参数名称 类型 是否必填 说明
    enableRegularNotification bool 是否开启消息提醒功能。
    enableRevokeMessageNotification bool 是否开启消息撤回提醒功能。

    示例代码

    dartNimCore.instance.settingsService.enableNotificationAndroid(
            enableRegularNotification: true,
            enableRevokeMessageNotification: false);
    

    返回值

    NIMResult<void>

    相关回调

    updateNotificationConfigAndroid

    接口描述

    更新通知栏配置,仅支持 Android 平台。

    参数说明

    dartFuture<NIMResult<void>> updateNotificationConfigAndroid(NIMStatusBarNotificationConfig config)
    
    参数名称 类型 是否必填 说明
    config NIMStatusBarNotificationConfig 通知栏配置。

    示例代码

    dartNimCore.instance.settingsService.updateNotificationConfigAndroid(config);
    

    返回值

    NIMResult<void>

    相关回调

    getPushMobileOnDesktopOnline

    接口描述

    获取当桌面端在线时,移动端是否需要推送。

    参数说明

    dartFuture<NIMResult<bool>> getPushMobileOnDesktopOnline()
    

    示例代码

    dartfinal isPush = (await NimCore.instance.settingsService.getPushMobileOnDesktopOnline()).data;
    

    返回值

    NIMResult<bool>:true表示需要推送,false 表示不需要

    相关回调

    onPushMobileOnDesktopOnline:当桌面端在线时,移动端是否需要推送的在线通知回调

    此文档是否对你有帮助?
    有帮助
    去反馈
    • API 概览
    • 系统设置监听
    • 系统设置操作
    • 接口类
    • listen
    • cancel
    • setP2PMessageMuteMode
    • getP2PMessageMuteMode
    • getP2PMessageMuteList
    • setTeamMessageMuteMode
    • getTeamMessageMuteMode
    • getConversationMuteStatus
    • setPushMobileOnDesktopOnline
    • setDndConfig
    • getDndConfig
    • enableNotificationAndroid
    • updateNotificationConfigAndroid
    • getPushMobileOnDesktopOnline