Android

设置群消息强制提醒

更新时间: 2024/03/14 16:36:34

云信 NIM SDK 支持对于群消息的强制提醒功能。

当发送方设置了该群消息的强制提醒,群消息接收者即使屏蔽了当前会话(如设置免打扰),仍能接收到该条消息提醒。

通过消息体的指定成员选项字段 MemberPushOption 来实现。

MemberPushOption 接口说明:

参数 类型 说明
ForcePush Boolean 是否强制提醒(仅针对 ForcePushList 中的账户),true 为强制提醒(默认),false 为不强制提醒
ForcePushList String 需要强制提醒的成员列表
如果填 null,表示强制提醒给该会话的所有成员,不为 null 时,最多可传入 100 个用户账号
ForcePushContent String 强制提醒的文案,最大长度 500 字符,如果设置为 nil,则使用消息本身的推送文案(pushContent
  • 对于 ForcePushList 中的用户,提醒文案使用 ForcePushContent;对于不在 ForcePushList 中的用户,使用推送文案 NIMMessage.pushContent
  • ForcePushList 中的账户的提醒文案又分两种情况.
    • ForcePush 为 true 时,提醒文案中不会包含发送者前缀(nick),直接为 ForcePushContent
    • ForcePush 为 false 时,提醒文案中目前包含了发送者的前缀(nick),即为 fromNick:ForcePushContent

示例代码如下:

// 该帐号为示例,请先注册
String account = "testAccount";
// 群聊才有强制提醒消息
SessionTypeEnum sessionType = SessionTypeEnum.Team;
String text = "指定消息";
// 创建一个文本消息
IMMessage textMessage = MessageBuilder.createTextMessage(account, sessionType, text);

// 强制提醒配置
MemberPushOption memberPushOption = new MemberPushOption();
// 开启强制提醒
memberPushOption.setForcePush(true);
// 设置强制提醒文案
memberPushOption.setForcePushContent(textMessage.getContent());
List<String> pushList = new ArrayList<>();
pushList.add("account1");
pushList.add("account2");
// 设置强制提醒的成员列表
memberPushOption.setForcePushList(pushList);
textMessage.setMemberPushOption(memberPushOption);

// 发送给对方
NIMClient.getService(MsgService.class).sendMessage(textMessage, false);
此文档是否对你有帮助?
有帮助
去反馈