全部文档

更新时间: 2020-08-26

# 本地删除

# 通过消息 ID 删除

通过消息 Id 删除本地一条或一组消息

参数说明

参数 类型 必填 说明
messageIds int[] 发送消息的 ID 数组
callback IRongCallback.ResultCallback<Boolean> 接口回调

代码示例

删除一条消息示例

int[] messageIds = {12}
RongIMClient.getInstance().deleteMessages(messageIds, new RongIMClient.ResultCallback<Boolean>() {
            /**
             * 删除消息成功回调
             */
            @Override
            public void onSuccess(Boolean bool) {
               
            }
            /**
             * 删除消息失败回调
             * @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

删除一组消息示例

int[] messageIds = {12, 13}
RongIMClient.getInstance().deleteMessages(messageIds, new RongIMClient.ResultCallback<Boolean>() {
             /**
             * 删除消息成功回调
             */
            @Override
            public void onSuccess(Boolean bool) {
               
            }
            /**
             * 删除消息失败回调
             * @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
# 通过时间戳删除

通过时间戳删除指定会话的聊天消息

参数说明

参数 类型 必填 说明
conversationType ConversationType (opens new window) 会话类型. 当前为 ConversationType.PRIVATE
targetId String 接收方的 userId
recordTime long 时间戳.
1. 传 0 清除所有消息
2. 非 0 则清除小于等于 recordTime 的消息
cleanRemote boolean 是否删除服务器端消息. true 删除, false 不删除
callback OperationCallback 接口回调

代码示例

ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "接收方的 userId";
String recordTime = 0;

RongIMClient.getInstance().cleanHistoryMessages(conversationType, targetId, recordTime, false, new RongIMClient.OperationCallback() {
    /**
     * 删除消息成功回调
     */
    @Override
    public void onSuccess() {
        
    }
    /**
     * 删除消息失败回调
     * @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
# 通过会话删除

删除指定会话中数据库的所有消息

参数说明

参数 类型 必填 说明
conversationType ConversationType (opens new window) 会话类型. 当前为 ConversationType.PRIVATE
targetId String 接收方的 userId
callback IRongCallback.ResultCallback<Boolean> 接口回调

代码示例

ConversationType conversationType = ConversationType.PRIVATE;
String targetId = "接收方的 userId";

RongIMClient.getInstance().deleteMessages(conversationType, targetId, new RongIMClient.ResultCallback<Boolean>() {
        /**
         * 删除消息成功回调
         */
        @Override
        public void onSuccess(Boolean bool) {
            
        }
        /**
         * 删除消息失败回调
         * @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

# 远端删除

# 通过会话删除

删除指定会话类型的目标 ID 的一条或者一组消息(服务器端),会同时删除本地和远端消息。

参数说明

参数 类型 必填 说明 最低版本
conversationType ConversationType (opens new window) 会话类型. 当前为 ConversationType.PRIVATE
targetId String 接收方的 userId
messages Message[] 要删除的消息数组
callback IRongCallback.ResultCallback<Boolean> 接口回调

代码示例

ConversationType conversationType = ConversationType.PRIVATE
String targetId = "接收方的 userId";
Message[] messages = {message1, message2}

RongIMClient.getInstance().deleteRemoteMessages(conversationType, targetId, messages, new RongIMClient.OperationCallback() {
    /**
     * 删除消息成功回调
     */
    @Override
    public void onSuccess() {
        
    }
    /**
     * 删除消息失败回调
     * @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
# 通过时间戳删除

通过时间戳删除指定会话,该时间之前的服务端历史消息,如需要同时删除本地消息需要再调用本地消息删除接口。

须先开通历史消息云存储功能

参数说明

参数 类型 必填 说明
conversationType ConversationType (opens new window) 会话类型. 当前为 ConversationType.PRIVATE
targetId String 接收方的 userId
recordTime long 时间戳.
1. 传 0 清除所有消息
2. 非 0 则清除小于等于 recordTime 的消息
callback OperationCallback 接口回调

代码示例

ConversationType conversationType = ConversationType.PRIVATE
String targetId = "接收方的 userId";
String recordTime = 0;

RongIMClient.getInstance().cleanRemoteHistoryMessages(conversationType, targetId, recordTime, new RongIMClient.OperationCallback() {
    /**
     * 删除消息成功回调
     */
    @Override
    public void onSuccess() {
        
    }
    /**
     * 删除消息失败回调
     * @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

文档是否解决您的问题 ?

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