更新时间: 2020-08-26
# 本地获取
指定 ConversationType.PRIVATE 会话类型以及 接收方的 userId 从本地存储分页获取聊天记录. 消息按照发送时间 sentTime 倒序排列.
# 参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
conversationType | ConversationType (opens new window) | 是 | 会话类型. 当前为 ConversationType.PRIVATE. |
targetId | String | 是 | 接收方的 userId |
lastMessageId | long | 是 | 当前消息列表中 sendTime 最小的消息ID. ID 不存在时, 应设置为-1 |
count | int | 是 | 每页消息的数量. 每页数量最多 20 条 |
callback | ResultCallback<List<Message>> | 是 | 接口回调 |
# 代码示例
ConversationType conversationType = ConversationType.PRIVATE; String targetId = "接收方的 userId"; int lastMessageId = -1; int count = 10; RongIMClient.getInstance().getHistoryMessages(conversationType, targetId, lastMessageId, count, new ResultCallback<List<Message>>() { /** * 成功时回调 * @param messages 获取的消息列表 */ @Override public void onSuccess(List<Message> messages) { } /** * 错误时回调。 * @param errorCode 错误码 */ @Override public void onError(ErrorCode errorCode) { } });
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 远端获取
指定 ConversationType.PRIVATE 会话类型以及 接收方的 userId 从服务器端分页获取聊天记录. 消息按照时间顺序从新到旧排列
历史消息需要在开发者后台 高级功能设置 (opens new window) 中开通 IM 商用版后, 开启 单群聊消息云存储
功能才可使用
# 参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
conversationType | ConversationType (opens new window) | 是 | 会话类型. 当前为 ConversationType.PRIVATE. |
targetId | String | 是 | 接收方的 userId |
dateTime | long | 是 | 获取消息时间点, 从 dataTime 开始获取消息.取值分两种情况: 1. 消息对象中的 sentTime. 2. 传 0 , 表示获取最新 count 条消息 |
count | int | 是 | 获取的消息数量. 每页数量最多 20 条 |
callback | ResultCallback<List<Message>> | 是 | 接口回调 |
# 代码示例
ConversationType conversationType = ConversationType.PRIVATE; String targetId = "接收方的 userId"; long dateTime = 0; int count = 20; RongIMClient.getInstance().getRemoteHistoryMessages(conversationType, targetId, dateTime, count, new ResultCallback<List<Message>>() { /** * 成功时回调 * @param messages 获取的消息列表 */ @Override public void onSuccess(List<Message> messages) { } /** * 错误时回调。 * @param errorCode 错误码 */ @Override public void onError(ErrorCode errorCode) { } });
已复制
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25