配置消息提醒功能
更新时间: 2024/03/07 13:22:03
NIM SDK 支持通过配置消息提醒的属性来设置消息提醒的多样化功能。
SDK 通过调用 updateNotificationConfigAndroid 方法更新通知栏消息提醒的配置项,包括提醒时是否需要亮灯,是否需要振动等。 具体的配置项请参考消息提醒配置项参考说明。
设置消息提醒文案
云信支持设置消息提醒的文案。消息提醒文案的使用优先级如下:
- 如果消息接收方设置的消息提醒文案显示属性为显示详情(
notificationConfig.hideContent= false),那么优先显示接收到的消息的推送文案(消息体中的pushContent字段内容),若发送方在发送消息时未设置消息的推送文案,则显示云信消息的内置文案(根据消息类型不同,内置文案不同,如文本消息类型对应的文案为“发来了一条消息”)。 - 如果消息接收方设置的消息提醒文案显示属性为不显示详情(
notificationConfig.hideContent= true),则使用默认的推送文案是:“你收到一条新消息”。
设置消息提醒通知栏跳转
通过配置 notificationConfig.notificationEntranceClassName 参数来设置通知栏提醒的响应 Intent 的 Activity。
示例代码如下:
//注意,此处应该填写类的全名
var config = NIMStatusBarNotificationConfig(notificationEntranceClassName: 'com.xxx.MainActivity');
var options = NIMAndroidSDKOptions(appKey: 'appKey',
//...
notificationConfig: config
//...
);
点击在线通知的通知栏传递的 extra 类型
点击在线通知的通知栏,会返回消息的详细信息,以便于后续进行页面跳转等操作。
通过配置 notificationConfig.notificationExtraType 来选择返回消息的类型,该参数的类型请参考NIMNotificationExtraType。
| NIMNotificationExtraType 枚举值 | 说明 |
|---|---|
| message | 返回消息提列表,ArrayList<IMMessage> 格式 |
| jsonArrStr | 返回 String 格式的 JSONArray,每个元素包含消息的uuid、sessionId、sessionType和time |
示例代码如下:
NIMStatusBarNotificationConfig(notificationEntranceClassName: 'com.netease.yunxin.app.flutter.im.MainActivity',
notificationExtraType:NIMNotificationExtraType.jsonArrStr);
设置消息提醒免打扰时段
云信 NIM SDK 支持全局的消息提醒免打扰。
当用户不需要在接收消息提醒,或者只需要接收某段时间的消息提醒时,用户可以通过以下两种方式实现。
-
调用
enableNotificationAndroid方法关闭消息提醒功能,关闭后,将不再接收消息提醒。NimCore.instance.settingsService.enableNotificationAndroid(enableRevokeMessageNotification: false,enableRegularNotification: false); -
在开启消息提醒功能的情况下通过配置
说明notificationConfig的以下参数来设置消息提醒的免打扰时段。参数 类型 downTimeToggle Boolean 消息提醒免打扰设置开关,默认为关闭(false) downTimeBegin String 消息提醒免打扰的开始时间,只有 `downTimeToggle` 为 true 时才有效,格式为北京时间的 24 小时计数 HH:mm downTimeEnd String 消息提醒免打扰的结束时间,只有 `downTimeToggle` 为 true 时才有效,格式为北京时间的 24 小时计数 HH:mm downTimeEnableNotification Boolean 消息提醒免打扰期间,是否显示通知,默认为显示(true) - 如果结束时间小于开始时间,那么免打扰时间为开始时间-24:00-结束时间。
- 若将
downTimeEnableNotification设置为 false,即表示在消息提醒免打扰期间,不显示通知。
消息提醒配置项参考说明
| notificationConfig 参数 | 说明 |
|---|---|
| vibrate | 是否需要振动提醒,默认为 true |
| ring | 是否需要响铃提醒,默认为 true |
| notificationSound | 响铃提醒的声音资源,如果不提供,使用系统默认提示音 |
| ledOnMs | 呼吸灯亮时的持续时间(毫秒) |
| ledOffMs | 呼吸灯熄灭时的持续时间(毫秒) |
| ledARGB | 呼吸灯的颜色 建议尽量使用绿色、蓝色、红色等基本颜色,避免使用混合色 |
| hideContent | 不显示消息详情开关,同时也不再显示消息发送者昵称。默认为 false |
| downTimeToggle | 免打扰设置开关,默认为关闭 |
| downTimeBegin | 免打扰的开始时间,格式为 HH:mm (24小时制) |
| downTimeEnd | 免打扰的结束时间,格式为 HH:mm(24小时制) 如果结束时间小于开始时间,免打扰时间为开始时间-24:00-结束时间 |
| downTimeEnableNotification | 免打扰期间,是否显示通知,默认为显示 |
| notificationColor | 消息通知栏颜色,将应用到 NotificationCompat.Builder 的 setColor 方法 |
| notificationEntranceClassName | 通知栏提醒的响应 intent 的 activity 类型,通过配置该参数实现消息提醒通知栏的跳转 若为 null,将使用包的 launcher 的入口 intent 的 activity |
| notificationExtraType | 点击在线通知的通知栏传递的 extra 类型
|
| notificationFoldStyle | 消息通知栏的折叠类型:
|
| showBadge | APP 图标是否显示未读数(红点) |
| titleOnlyShowAppName | 通知栏提醒的标题是否只显示应用名,默认 false
|
| customTitleWhenTeamNameEmpty | 通知栏标题,如果群名称为 null 或者空串,则使用该字段作为通知栏 title |
此文档是否对你有帮助?






