全部文档

更新时间: 2021-03-08

# 功能描述

开发者可通过下面方法在会话页面内插入一条消息。通过此方法插入的消息,会将消息实体对应的内容插入数据源中,并更新 UI。

# 插入发送消息

本地会话中插入一条消息,方向为发送.消息不会实际发送给服务器和对方. 插入消息后, 会自定刷新 UI 界面.

插入消息需为入库消息. 自定义消息的 MessageTag (opens new window) 需为 MessageTag.ISPERSISTED,否者 ErrorCode.PARAMETER_ERROR参数错误}

# 参数说明
参数 类型 必填 说明
conversationType ConversationType (opens new window) 会话类型. 当前为 ConversationType.PRIVATE
targetId String 接收方 ID
sentStatus Message.SentStatus (opens new window) 发送状态
content MessageContent 消息内容
sentTime long 消息的发送时间, 需填写
callback IRongCallback.ResultCallback<Message> 回调接口
# 代码示例
ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "接收方 ID";
SentStatus sentStatus = SentStatus.SENT;
String content = "这是一条插入数据";
String sentTime = System.currentTimeMillis();

RongIM.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

# 插入接收消息

本地会话中插入一条消息,方向为接收.消息不会实际发送给服务器和对方

插入消息需为入库消息. 自定义消息的 MessageTag (opens new window) 需为 MessageTag.ISPERSISTED,否则报参数错误异常.

# 参数说明
参数 类型 必填 说明
conversationType ConversationType (opens new window) 会话类型. 当前为 ConversationType.PRIVATE.
targetId String 接收方 ID
senderUserId String 发送方 ID
receivedStatus Message.ReceivedStatus (opens new window) 接收状态
content MessageContent 消息内容
sentTime long 消息的发送时间, 需填写
callback IRongCallback.ResultCallback<Message> 回调接口
# 代码示例
ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "接收方 ID";
String senderUserId = "模拟发送方的 ID";
ReceivedStatus receivedStatus = new ReceivedStatus(0x1);
String content = "这是一条插入数据";
String sentTime = System.currentTimeMillis();

RongIMC.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

文档是否解决您的问题 ?

如果遇到产品相关问题,您可 提交工单 寻求帮助