更新时间: 2020-08-26
# 插入发送消息
本地会话中插入一条消息,方向为发送. 消息不会实际发送给服务器和对方.
插入消息需为入库消息. 自定义消息的 MessageTag (opens new window) 需为 MessageTag.ISPERSISTED
,否则报参数错误异常.
# 参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
conversationType | ConversationType (opens new window) | 是 | 会话类型. 当前为 ConversationType.PRIVATE. |
targetId | String | 是 | 接收方的 userId |
sentStatus | Message.SentStatus (opens new window) | 是 | 发送状态 |
content | MessageContent (opens new window) | 是 | 消息内容 |
sentTime | long | 是 | 消息的发送时间, 需填写 |
callback | IRongCallback.ResultCallback<Message (opens new window)> | 是 | 回调接口 |
# 代码示例
ConversationType conversationType = ConversationType.PRIVATE; String targetId = "接收方的 userId"; SentStatus sentStatus = SentStatus.SENT; TextMessage content = TextMessage.obtain("这里是消息内容"); String sentTime = System.currentTimeMillis(); RongIMClient.getInstance().insertOutgoingMessage(conversationType, targetId, sentStatus, content, sentTime, new RongIMClient.ResultCallback<Message>() { /** * 成功回调 * @param message 插入的消息 */ @Override public void onSuccess(Message message) { } /** * 失败回调 * @param errorCode 错误码 */ @Override public void onError(RongIMClient.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
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 插入接收消息
本地会话中插入一条消息,方向为接收.消息不会实际发送给服务器和对方
插入消息需为入库消息. 自定义消息的 MessageTag (opens new window) 需为 MessageTag.ISPERSISTED
,否则报参数错误异常.
# 参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
conversationType | ConversationType (opens new window) | 是 | 会话类型. 当前为 ConversationType.PRIVATE. |
targetId | String | 是 | 接收方的 userId |
senderUserId | String | 是 | 发送方 ID |
receivedStatus | Message.ReceivedStatus (opens new window) | 是 | 接收状态 |
content | MessageContent | 是 | 消息内容 |
sentTime | long | 是 | 消息的发送时间, 需填写 |
callback | IRongCallback.ResultCallback<Message> | 是 | 回调接口 |
# 代码示例
ConversationType conversationType = ConversationType.PRIVATE; String targetId = "接收方的 userId"; String senderUserId = "模拟发送方的 ID"; ReceivedStatus receivedStatus = new ReceivedStatus(0x1); String content = "这是一条插入数据"; String sentTime = System.currentTimeMillis(); RongIMClient.getInstance().insertIncomingMessage(conversationType, targetId, senderUserId, receivedStatus, content, sentTime, new RongIMClient.ResultCallback<Message>() { /** * 成功回调 * @param message 插入的消息 */ @Override public void onSuccess(Message message) { } /** * 失败回调 * @param errorCode 错误码 */ @Override public void onError(RongIMClient.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
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26