Class IMCenter
-
- All Implemented Interfaces:
public class IMCenter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enum
IMCenter.VoiceMessageType
语音消息类型
public interface
IMCenter.FilterSentListener
-
Method Summary
Modifier and Type Method Description static IMCenter
getInstance()
static void
init(Application application, String appKey, boolean isEnablePush)
初始化 SDK,在整个应用程序全局,只需要调用一次。 static void
init(Application application, String appKey, InitOption option)
初始化 SDK,在整个应用程序全局,只需要调用一次。 static void
init(Application application, String appKey, boolean isEnablePush, Boolean isMainProcess)
初始化 SDK,在整个应用程序全局,只需要调用一次。 static void
setConversationClickListener(ConversationClickListener listener)
设置会话界面操作的监听器。 static void
setConversationListBehaviorListener(ConversationListBehaviorListener listener)
设置会话列表界面操作的监听器。 void
connect(String token, int timeLimit, ConnectCallback connectCallback)
连接服务器,在整个应用程序全局,只需要调用一次。 调用该接口,SDK 会在 timeLimit 秒内尝试重连,直到出现下面三种情况之一: 第一、连接成功,回调 onSuccess(userId)。 第二、超时,回调 onError(RC_CONNECT_TIMEOUT),并不再重连。 第三、出现 SDK 无法处理的错误,回调 onError(errorCode)(如 token 非法),并不再重连。 连接成功后,SDK 将接管所有的重连处理。当因为网络原因断线的情况下,SDK 会不停重连直到连接成功为止,不需要您做额外的连接操作。 boolean
isInitialized()
返回 SDK 是否已经初始化。 void
)>clearMessages(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
根据会话类型,清空某一会话的所有聊天消息记录,回调方式获取清空是否成功。 void
connect(String token, ConnectCallback connectCallback)
void
recallMessage(Message message, String pushContent, ResultCallback callback)
撤回消息 ConnectionStatus
getCurrentConnectionStatus()
void
sendMessage(ConversationType type, String targetId, MessageContent content, String pushContent, String pushData, ISendMessageCallback callback)
根据会话类型,发送消息。 通过 IRongCallback. void
sendMessage(Message message, String pushContent, String pushData, ISendMessageCallback callback)
发送消息。 通过 IRongCallback. void
sendMessage(Message message, String pushContent, String pushData, SendMessageOption option, ISendMessageCallback callback)
发送消息。 通过 IRongCallback. void
sendReadReceiptMessage(ConversationType conversationType, String targetId, long timestamp, ISendMessageCallback callback)
发送已读回执,该方法会触发刷新消息未读数 通过 IRongCallback. void
syncConversationReadStatus(ConversationType type, String targetId, long timestamp, OperationCallback callback)
同步会话阅读状态。 void
syncConversationReadStatus(ConversationIdentifier conversationIdentifier, long timestamp, OperationCallback callback)
同步会话阅读状态。 void
sendMediaMessage(Message message, String pushContent, String pushData, ISendMediaMessageCallback callback)
发送消息。 通过 IRongCallback. void
sendMediaMessage(Message message, String pushContent, String pushData, SendMessageOption option, ISendMediaMessageCallback callback)
发送消息。 通过 IRongCallback. void
sendMediaMessage(Message message, String pushContent, String pushData, ISendMediaMessageCallbackWithUploader callback)
void
sendMediaMessage(Message message, String pushContent, String pushData, SendMessageOption option, ISendMediaMessageCallbackWithUploader callback)
void
sendDirectionalMessage(ConversationType type, String targetId, MessageContent content, Array<String> userIds, String pushContent, String pushData, ISendMessageCallback callback)
发送定向消息。向会话中特定的某些用户发送消息,会话中其他用户将不会收到此消息。 通过 IRongCallback. void
sendDirectionalMessage(Message message, Array<String> userIds, String pushContent, String pushData, ISendMessageCallback callback)
void
sendDirectionalMediaMessage(Message message, Array<String> userIds, String pushContent, String pushData, ISendMediaMessageCallback callback)
发送定向多媒体消息 向会话中特定的某些用户发送消息,会话中其他用户将不会收到此消息。 发送前构造 Message 消息实体,消息实体中的 content 必须为多媒体消息,如 ImageMessage或者其他继承自 MediaMessageContent 的消息 从 5.6. void
cleanHistoryMessages(ConversationType conversationType, String targetId, long recordTime, boolean cleanRemote, OperationCallback callback)
删除指定时间戳之前的消息,可选择是否同时删除服务器端消息 此方法可从服务器端清除历史消息,但是必须先开通历史消息云存储功能。 根据会话类型和会话 id 清除某一会话指定时间戳之前的本地数据库消息(服务端历史消息), 清除成功后只能从本地数据库(服务端)获取到该时间戳之后的历史消息。 void
cleanHistoryMessages(ConversationIdentifier conversationIdentifier, long recordTime, boolean cleanRemote, OperationCallback callback)
删除指定时间戳之前的消息,可选择是否同时删除服务器端消息 此方法可从服务器端清除历史消息,但是必须先开通历史消息云存储功能。 根据会话类型和会话 id 清除某一会话指定时间戳之前的本地数据库消息(服务端历史消息), 清除成功后只能从本地数据库(服务端)获取到该时间戳之后的历史消息。 void
)>clearMessagesUnreadStatus(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
清除某会话的消息未读状态 void
)>clearMessagesUnreadStatus(ConversationIdentifier conversationIdentifier, ResultCallback<Boolean> callback)
清除某会话的消息未读状态 void
)>clearTextMessageDraft(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
清除某一会话的文字消息草稿,回调方式获取清除是否成功。 void
)>saveTextMessageDraft(ConversationType conversationType, String targetId, String content, ResultCallback<Boolean> callback)
保存文字消息草稿,回调方式获取保存是否成功。 void
)>saveTextMessageDraft(ConversationIdentifier conversationIdentifier, String content, ResultCallback<Boolean> callback)
保存文字消息草稿,回调方式获取保存是否成功。 void
)>removeConversation(ConversationType type, String targetId, ResultCallback<Boolean> callback)
从会话列表中移除某一会话,但是不删除会话内的消息。 如果此会话中有新的消息,该会话将重新在会话列表中显示,并显示最近的历史消息。 void
)>setConversationToTop(ConversationIdentifier conversationIdentifier, boolean isTop, ResultCallback<Boolean> callback)
设置某一会话为置顶或者取消置顶,回调方式获取设置是否成功。 void
)>setConversationToTop(ConversationType type, String targetId, boolean isTop, boolean needCreate, ResultCallback<Boolean> callback)
设置某一会话为置顶或者取消置顶,回调方式获取设置是否成功。 void
)>setConversationToTop(ConversationIdentifier conversationIdentifier, boolean isTop, boolean needCreate, ResultCallback<Boolean> callback)
设置某一会话为置顶或者取消置顶,回调方式获取设置是否成功。 void
)>setConversationNotificationStatus(ConversationType conversationType, String targetId, ConversationNotificationStatus notificationStatus, ResultCallback<ConversationNotificationStatus> callback)
设置会话消息提醒状态。 void
)>setConversationNotificationStatus(ConversationIdentifier conversationIdentifier, ConversationNotificationStatus notificationStatus, ResultCallback<ConversationNotificationStatus> callback)
设置会话消息提醒状态。 void
)>insertOutgoingMessage(ConversationType type, String targetId, SentStatus sentStatus, MessageContent content, ResultCallback<Message> resultCallback)
向本地会话中插入一条消息,方向为发送。这条消息只是插入本地会话,不会实际发送给服务器和对方。 插入消息需为入库消息,即 ISPERSISTED,否者会回调 PARAMETER_ERROR void
)>insertOutgoingMessage(ConversationType type, String targetId, SentStatus sentStatus, MessageContent content, long time, ResultCallback<Message> resultCallback)
void
)>insertOutgoingMessage(ConversationIdentifier conversationIdentifier, SentStatus sentStatus, MessageContent content, long time, ResultCallback<Message> resultCallback)
向本地会话中插入一条消息,方向为发送。这条消息只是插入本地会话,不会实际发送给服务器和对方。 插入消息需为入库消息,即 ISPERSISTED,否者会回调 PARAMETER_ERROR void
)>insertIncomingMessage(ConversationType type, String targetId, String senderId, ReceivedStatus receivedStatus, MessageContent content, ResultCallback<Message> resultCallback)
void
)>insertIncomingMessage(ConversationType type, String targetId, String senderId, ReceivedStatus receivedStatus, MessageContent content, long time, ResultCallback<Message> resultCallback)
void
)>deleteMessages(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
清除指定会话的消息。 此接口会删除指定会话中数据库的所有消息,同时,会清理数据库空间。 如果数据库特别大,超过几百 M,调用该接口会有少许耗时。 void
)>deleteMessages(ConversationType conversationType, String targetId, Array<int> messageIds, ResultCallback<Boolean> callback)
删除会话里的一条或多条消息。 void
deleteRemoteMessages(ConversationType conversationType, String targetId, Array<Message> messages, OperationCallback callback)
删除指定的一条或者一组消息。会同时删除本地和远端消息。 请注意,此方法会删除远端消息,请慎重使用 5.6.9版本以下不支持超级群会话类型,从 5.6. void
deleteRemoteMessages(ConversationIdentifier identifier, Array<Message> messages, OperationCallback callback)
删除指定的一条或者一组消息。会同时删除本地和远端消息。 请注意,此方法会删除远端消息,请慎重使用 5.6.9版本以下不支持超级群会话类型,从 5.6. void
disconnect()
断开连接(断开后继续接收 Push 消息)。 void
downloadMedia(ConversationType conversationType, String targetId, MediaType mediaType, String imageUrl, DownloadMediaCallback callback)
下载文件。 用来获取媒体原文件时调用。如果本地缓存中包含此文件,则从本地缓存中直接获取,否则将从服务器端下载。 void
downloadMediaFile(String uid, String fileUrl, String fileName, String path, IDownloadMediaFileCallback callback)
下载文件 支持断点续传 void
cancelDownloadMediaMessage(Message message, OperationCallback callback)
取消下载多媒体文件。 void
clearConversations(ResultCallback callback, Array<ConversationType> conversationTypes)
清空所有会话及会话内的消息,回调方式通知是否清空成功。 void
downloadMediaMessage(Message message, IDownloadMediaMessageCallback callback)
下载文件 用来获取媒体原文件时调用。如果本地缓存中包含此文件,则从本地缓存中直接获取,否则将从服务器端下载。 void
logout()
注销当前登录,执行该方法后不会再收到 push 消息。 void
setMessageInterceptor(MessageInterceptor messageInterceptor)
设置接收消息时的拦截器 void
)>supportResumeBrokenTransfer(String url, ResultCallback<Boolean> callback)
判断是否支持断点续传。 void
pauseDownloadMediaMessage(Message message, OperationCallback callback)
暂停下载多媒体文件 void
refreshMessage(Message message)
通知会话页面刷新某条消息 Context
getContext()
void
sendLocationMessage(Message message, String pushContent, String pushData, ISendMessageCallback sendMessageCallback)
发送地理位置消息。并同时更新界面。 发送前构造 Message 消息实体,消息实体中的 content 必须为 LocationMessage, 否则返回失败。 其中的缩略图地址 scheme 只支持 file:// 和 http:// 其他暂不支持。 void
)>setMessageSentStatus(Message message, ResultCallback<Boolean> callback)
根据消息 Message 设置消息状态,回调方式获取设置是否成功。 void
handleBeforeSend(Message message)
发送消息之前的内部逻辑处理。 void
cancelSendMediaMessage(Message message, OperationCallback callback)
取消发送多媒体文件。 void
changeMessageReceivedStatus(int messageId, ConversationType conversationType, String targetId, ReceivedStatus status)
void
addOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
void
removeOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
void
addAsyncOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
void
removeAsyncOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
void
addSyncConversationReadStatusListener(SyncConversationReadStatusListener listener)
void
removeSyncConversationReadStatusListeners(SyncConversationReadStatusListener listener)
void
addConnectStatusListener(ConnectCallback callback)
void
removeConnectStatusListener(ConnectCallback callback)
void
addConnectionStatusListener(ConnectionStatusListener listener)
设置连接状态变化的监听器。 当回调状态为TOKEN_INCORRECT, 需要获取正确的token, 并主动调用connect void
removeConnectionStatusListener(ConnectionStatusListener listener)
移除连接状态监听器 void
addConversationEventListener(ConversationEventListener listener)
void
removeConversationEventListener(ConversationEventListener listener)
void
addMessageEventListener(MessageEventListener listener)
void
removeMessageEventListener(MessageEventListener listener)
void
addConversationStatusListener(ConversationStatusListener listener)
void
removeConversationStatusListener(ConversationStatusListener listener)
void
addOnRecallMessageListener(OnRecallMessageListener listener)
void
removeOnRecallMessageListener(OnRecallMessageListener listener)
void
addReadReceiptListener(ReadReceiptListener listener)
void
removeReadReceiptListener(ReadReceiptListener listener)
void
addTypingStatusListener(TypingStatusListener listener)
void
removeTypingStatusListener(TypingStatusListener listener)
void
)>addCancelSendMediaMessageListener(ResultCallback<Message> listener)
void
)>removeCancelSendMediaMessageListener(ResultCallback<Message> listener)
-
-
Method Detail
-
getInstance
static IMCenter getInstance()
-
init
static void init(Application application, String appKey, boolean isEnablePush)
初始化 SDK,在整个应用程序全局,只需要调用一次。
- Parameters:
application
- 应用上下文。appKey
- 在融云开发者后台注册的应用 AppKey。isEnablePush
- 是否使用推送功能
-
init
static void init(Application application, String appKey, InitOption option)
初始化 SDK,在整个应用程序全局,只需要调用一次。
- Parameters:
application
- 应用上下文。appKey
- 在融云开发者后台注册的应用 AppKey。option
- 初始化所需要的配置信息,详情可参考 InitOption- Since:
5.4.1
-
init
static void init(Application application, String appKey, boolean isEnablePush, Boolean isMainProcess)
初始化 SDK,在整个应用程序全局,只需要调用一次。
- Parameters:
application
- 应用上下文。appKey
- 在融云开发者后台注册的应用 AppKey。isEnablePush
- 是否使用推送功能isMainProcess
- 是否为主进程。如果为null,则代表由SDK判断进程
-
setConversationClickListener
static void setConversationClickListener(ConversationClickListener listener)
设置会话界面操作的监听器。
- Parameters:
listener
- 会话界面操作的监听器。
-
setConversationListBehaviorListener
static void setConversationListBehaviorListener(ConversationListBehaviorListener listener)
设置会话列表界面操作的监听器。
- Parameters:
listener
- 会话列表界面操作的监听器。
-
connect
void connect(String token, int timeLimit, ConnectCallback connectCallback)
连接服务器,在整个应用程序全局,只需要调用一次。
调用该接口,SDK 会在 timeLimit 秒内尝试重连,直到出现下面三种情况之一: 第一、连接成功,回调 onSuccess(userId)。 第二、超时,回调 onError(RC_CONNECT_TIMEOUT),并不再重连。 第三、出现 SDK 无法处理的错误,回调 onError(errorCode)(如 token 非法),并不再重连。 连接成功后,SDK 将接管所有的重连处理。当因为网络原因断线的情况下,SDK 会不停重连直到连接成功为止,不需要您做额外的连接操作。
- Parameters:
token
- 从服务端获取的 用户身份令牌( Token)。timeLimit
- 连接超时时间,单位:秒。timeLimit <= 0
,则 IM 将一直连接,直到连接成功或者无法连接(如token
非法)timeLimit > 0
,则 IM 将最多连接 timeLimit 秒: 如果在 timeLimit 秒内连接成功,后面再发生了网络变化或前后台切换,SDK 会自动重连; 如果在 timeLimit 秒无法连接成功则不再进行重连,通过 onError 告知连接超时,您需要再自行调用 connect 接口connectCallback
- 连接服务器的回调扩展类,新增打开数据库的回调,用户可以在此回调中执行拉取会话列表操作。 该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
isInitialized
boolean isInitialized()
返回 SDK 是否已经初始化。
- Returns:
true 代表已经初始化;false 未初始化。
-
clearMessages
void )>clearMessages(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
根据会话类型,清空某一会话的所有聊天消息记录,回调方式获取清空是否成功。
- Parameters:
conversationType
- 会话类型。不支持传入 ConversationType.targetId
- 目标 Id。根据不同的 conversationType,可能是用户 Id、讨论组 Id、群组 Id。callback
- 清空是否成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
connect
void connect(String token, ConnectCallback connectCallback)
-
recallMessage
void recallMessage(Message message, String pushContent, ResultCallback callback)
撤回消息
- Parameters:
message
- 将被撤回的消息pushContent
- 被撤回时,通知栏显示的信息callback
- 成功回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
getCurrentConnectionStatus
ConnectionStatus getCurrentConnectionStatus()
-
sendMessage
void sendMessage(ConversationType type, String targetId, MessageContent content, String pushContent, String pushData, ISendMessageCallback callback)
根据会话类型,发送消息。
通过 IRongCallback.ISendMessageCallback 中的方法回调发送的消息状态及消息体。注意:1 秒钟发送消息不能超过 5 条。
- Parameters:
type
- 会话类型。targetId
- 会话 id。根据不同的 conversationType,可能是用户 id、讨论组 id、群组 id 或聊天室 id。content
- 消息内容,例如 TextMessage, ImageMessage。pushContent
- 当下发远程推送消息时,在通知栏里会显示这个字段。 如果发送的是自定义消息,该字段必须填写,否则无法收到远程推送消息。 如果发送 SDK 中默认的消息类型,例如 RC:TxtMsg, RC:VcMsg, RC:ImgMsg,则不需要填写,默认已经指定。pushData
- 远程推送附加信息。如果设置该字段,用户在收到 push 消息时,能通过 getPushData 方法获取。callback
- 发送消息的回调。参考 IRongCallback.
-
sendMessage
void sendMessage(Message message, String pushContent, String pushData, ISendMessageCallback callback)
发送消息。 通过 IRongCallback.ISendMessageCallback 中的方法回调发送的消息状态及消息体。
- Parameters:
message
- 将要发送的消息体。pushContent
- 当下发 push 消息时,在通知栏里会显示这个字段。 如果发送的是自定义消息,该字段必须填写,否则无法收到 push 消息。 如果发送 sdk 中默认的消息类型,例如 RC:TxtMsg, RC:VcMsg, RC:ImgMsg,则不需要填写,默认已经指定。pushData
- push 附加信息。如果设置该字段,用户在收到 push 消息时,能通过 getPushData 方法获取。callback
- 发送消息的回调,参考 IRongCallback.
-
sendMessage
void sendMessage(Message message, String pushContent, String pushData, SendMessageOption option, ISendMessageCallback callback)
发送消息。 通过 IRongCallback.ISendMessageCallback 中的方法回调发送的消息状态及消息体。
- Parameters:
message
- 将要发送的消息体。pushContent
- 当下发 push 消息时,在通知栏里会显示这个字段。 如果发送的是自定义消息,该字段必须填写,否则无法收到 push 消息。 如果发送 sdk 中默认的消息类型,例如 RC:TxtMsg, RC:VcMsg, RC:ImgMsg,则不需要填写,默认已经指定。pushData
- push 附加信息。如果设置该字段,用户在收到 push 消息时,能通过 getPushData 方法获取。callback
- 发送消息的回调,参考 IRongCallback.
-
sendReadReceiptMessage
void sendReadReceiptMessage(ConversationType conversationType, String targetId, long timestamp, ISendMessageCallback callback)
发送已读回执,该方法会触发刷新消息未读数
通过 IRongCallback.ISendMessageCallback 中的方法回调发送的消息状态及消息体。注意:1 秒钟发送消息不能超过 5 条。
- Parameters:
conversationType
- 会话类型。targetId
- 会话 id。根据不同的 conversationType,可能是用户 id、讨论组 id、群组 id 或聊天室 id。timestamp
- 时间戳callback
- 发送消息的回调。参考 IRongCallback.
-
syncConversationReadStatus
void syncConversationReadStatus(ConversationType type, String targetId, long timestamp, OperationCallback callback)
同步会话阅读状态。
- Parameters:
type
- 会话类型targetId
- 会话 idtimestamp
- 会话中已读的最后一条消息的发送时间戳 getSentTimecallback
- 回调函数。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
syncConversationReadStatus
void syncConversationReadStatus(ConversationIdentifier conversationIdentifier, long timestamp, OperationCallback callback)
同步会话阅读状态。
- Parameters:
conversationIdentifier
- 会话标识timestamp
- 会话中已读的最后一条消息的发送时间戳 getSentTimecallback
- 回调函数。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
sendMediaMessage
void sendMediaMessage(Message message, String pushContent, String pushData, ISendMediaMessageCallback callback)
发送消息。 通过 IRongCallback.ISendMessageCallback 中的方法回调发送的消息状态及消息体。
- Parameters:
message
- 将要发送的消息体。pushContent
- 当下发 push 消息时,在通知栏里会显示这个字段。 如果发送的是自定义消息,该字段必须填写,否则无法收到 push 消息。 如果发送 sdk 中默认的消息类型,例如 RC:TxtMsg, RC:VcMsg, RC:ImgMsg,则不需要填写,默认已经指定。pushData
- push 附加信息。如果设置该字段,用户在收到 push 消息时,能通过 getPushData 方法获取。callback
- 发送消息的回调,参考 IRongCallback.
-
sendMediaMessage
void sendMediaMessage(Message message, String pushContent, String pushData, SendMessageOption option, ISendMediaMessageCallback callback)
发送消息。 通过 IRongCallback.ISendMessageCallback 中的方法回调发送的消息状态及消息体。
- Parameters:
message
- 将要发送的消息体。pushContent
- 当下发 push 消息时,在通知栏里会显示这个字段。 如果发送的是自定义消息,该字段必须填写,否则无法收到 push 消息。 如果发送 sdk 中默认的消息类型,例如 RC:TxtMsg, RC:VcMsg, RC:ImgMsg,则不需要填写,默认已经指定。pushData
- push 附加信息。如果设置该字段,用户在收到 push 消息时,能通过 getPushData 方法获取。option
- 发送消息附加选项,目前仅支持设置 isVoIPPush,如果对端设备是 iOS,设置 isVoIPPush 为 True,会走 VoIP 通道推送 Push。callback
- 发送消息的回调,参考 IRongCallback.- Since:
5.4.4
-
sendMediaMessage
void sendMediaMessage(Message message, String pushContent, String pushData, ISendMediaMessageCallbackWithUploader callback)
-
sendMediaMessage
void sendMediaMessage(Message message, String pushContent, String pushData, SendMessageOption option, ISendMediaMessageCallbackWithUploader callback)
-
sendDirectionalMessage
void sendDirectionalMessage(ConversationType type, String targetId, MessageContent content, Array<String> userIds, String pushContent, String pushData, ISendMessageCallback callback)
发送定向消息。向会话中特定的某些用户发送消息,会话中其他用户将不会收到此消息。 通过 IRongCallback.ISendMessageCallback 中的方法回调发送的消息状态及消息体。 此方法只能发送非多媒体消息,多媒体消息如ImageMessageFileMessage ,或者继承自的消息须调用 sendDirectionalMediaMessage。
从 5.6.9 版本开始,支持超级群会话类型。
- Parameters:
type
- 会话类型。targetId
- 目标 Id。根据不同的 conversationType,可能是群组 Id 、超级群 Id。content
- 消息内容,例如 TextMessageuserIds
- 会话中将会接收到此消息的用户列表。pushContent
- 当下发 push 消息时,在通知栏里会显示这个字段。 如果发送的是自定义消息,该字段必须填写,否则无法收到 push 消息。 如果发送 sdk 中默认的消息类型,例如 RC:TxtMsg, RC:VcMsg, RC:ImgMsg,则不需要填写,默认已经指定。pushData
- push 附加信息。如果设置该字段,用户在收到 push 消息时,能通过 getPushData 方法获取。callback
- 发送消息的回调,参考 IRongCallback.
-
sendDirectionalMessage
void sendDirectionalMessage(Message message, Array<String> userIds, String pushContent, String pushData, ISendMessageCallback callback)
-
sendDirectionalMediaMessage
void sendDirectionalMediaMessage(Message message, Array<String> userIds, String pushContent, String pushData, ISendMediaMessageCallback callback)
发送定向多媒体消息 向会话中特定的某些用户发送消息,会话中其他用户将不会收到此消息。
发送前构造 Message 消息实体,消息实体中的 content 必须为多媒体消息,如 ImageMessage
或者其他继承自 MediaMessageContent 的消息
从 5.6.9 版本开始,支持超级群会话类型。
- Parameters:
message
- 发送消息的实体。userIds
- 定向接收者 id 数组pushContent
- 当下发 push 消息时,在通知栏里会显示这个字段。 发送文件消息时,此字段必须填写,否则会收不到 push 推送。pushData
- push 附加信息。如果设置该字段,用户在收到 push 消息时,能通过 getPushData 方法获取。callback
- 发送消息的回调 RongIMClient.
-
cleanHistoryMessages
void cleanHistoryMessages(ConversationType conversationType, String targetId, long recordTime, boolean cleanRemote, OperationCallback callback)
删除指定时间戳之前的消息,可选择是否同时删除服务器端消息
此方法可从服务器端清除历史消息,但是必须先开通历史消息云存储功能。 根据会话类型和会话 id 清除某一会话指定时间戳之前的本地数据库消息(服务端历史消息), 清除成功后只能从本地数据库(服务端)获取到该时间戳之后的历史消息。
- Parameters:
conversationType
- 会话类型。targetId
- 会话 id。recordTime
- 清除消息截止时间戳,0 <= recordTime <=
当前会话最后一条消息的 sentTime,0 清除所有消息,其他值清除小于等于 recordTime 的消息。cleanRemote
- 是否删除服务器端消息callback
- 清除消息的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
cleanHistoryMessages
void cleanHistoryMessages(ConversationIdentifier conversationIdentifier, long recordTime, boolean cleanRemote, OperationCallback callback)
删除指定时间戳之前的消息,可选择是否同时删除服务器端消息
此方法可从服务器端清除历史消息,但是必须先开通历史消息云存储功能。 根据会话类型和会话 id 清除某一会话指定时间戳之前的本地数据库消息(服务端历史消息), 清除成功后只能从本地数据库(服务端)获取到该时间戳之后的历史消息。
- Parameters:
conversationIdentifier
- 会话标识。recordTime
- 清除消息截止时间戳,0 <= recordTime <=
当前会话最后一条消息的 sentTime,0 清除所有消息,其他值清除小于等于 recordTime 的消息。cleanRemote
- 是否删除服务器端消息callback
- 清除消息的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
clearMessagesUnreadStatus
void )>clearMessagesUnreadStatus(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
清除某会话的消息未读状态
- Parameters:
conversationType
- 会话类型。不支持传入 ConversationType.targetId
- 目标 Id。根据不同的 conversationType,可能是用户 Id、讨论组 Id、群组 Id。callback
- 清除是否成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
clearMessagesUnreadStatus
void )>clearMessagesUnreadStatus(ConversationIdentifier conversationIdentifier, ResultCallback<Boolean> callback)
清除某会话的消息未读状态
- Parameters:
conversationIdentifier
- 会话标识。callback
- 清除是否成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
clearTextMessageDraft
void )>clearTextMessageDraft(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
清除某一会话的文字消息草稿,回调方式获取清除是否成功。
- Parameters:
conversationType
- 会话类型。targetId
- 目标 Id。根据不同的 conversationType,可能是用户 Id、讨论组 Id、群组 Id 或聊天室 Id。callback
- 是否清除成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
saveTextMessageDraft
void )>saveTextMessageDraft(ConversationType conversationType, String targetId, String content, ResultCallback<Boolean> callback)
保存文字消息草稿,回调方式获取保存是否成功。
- Parameters:
conversationType
- 会话类型。targetId
- 目标 Id。根据不同的 conversationType,可能是用户 Id、讨论组 Id、群组 Id 或聊天室 Id。content
- 草稿的文字内容。callback
- 是否保存成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
saveTextMessageDraft
void )>saveTextMessageDraft(ConversationIdentifier conversationIdentifier, String content, ResultCallback<Boolean> callback)
保存文字消息草稿,回调方式获取保存是否成功。
- Parameters:
conversationIdentifier
- 会话标识。content
- 草稿的文字内容。callback
- 是否保存成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
removeConversation
void )>removeConversation(ConversationType type, String targetId, ResultCallback<Boolean> callback)
从会话列表中移除某一会话,但是不删除会话内的消息。
如果此会话中有新的消息,该会话将重新在会话列表中显示,并显示最近的历史消息。
- Parameters:
type
- 会话类型。targetId
- 目标 Id。根据不同的 conversationType,可能是用户 Id、讨论组 Id、群组 Id 或聊天室 Id。callback
- 移除会话是否成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
setConversationToTop
void )>setConversationToTop(ConversationIdentifier conversationIdentifier, boolean isTop, ResultCallback<Boolean> callback)
设置某一会话为置顶或者取消置顶,回调方式获取设置是否成功。
- Parameters:
conversationIdentifier
- 会话标识。isTop
- 是否置顶。callback
- 设置置顶或取消置顶是否成功的回调。 该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。- Since:
5.6.8
-
setConversationToTop
@Deprecated() void )>setConversationToTop(ConversationType type, String targetId, boolean isTop, boolean needCreate, ResultCallback<Boolean> callback)
设置某一会话为置顶或者取消置顶,回调方式获取设置是否成功。
- Parameters:
type
- 会话类型。targetId
- 目标 Id。根据不同的 conversationType,可能是用户 Id、讨论组 Id、群组 Id 或聊天室 Id。isTop
- 是否置顶。needCreate
- 会话不存在时,是否创建会话。callback
- 设置置顶或取消置顶是否成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
setConversationToTop
@Deprecated() void )>setConversationToTop(ConversationIdentifier conversationIdentifier, boolean isTop, boolean needCreate, ResultCallback<Boolean> callback)
设置某一会话为置顶或者取消置顶,回调方式获取设置是否成功。
- Parameters:
conversationIdentifier
- 会话标识。isTop
- 是否置顶。needCreate
- 会话不存在时,是否创建会话。callback
- 设置置顶或取消置顶是否成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
setConversationNotificationStatus
void )>setConversationNotificationStatus(ConversationType conversationType, String targetId, ConversationNotificationStatus notificationStatus, ResultCallback<ConversationNotificationStatus> callback)
设置会话消息提醒状态。
- Parameters:
conversationType
- 会话类型。targetId
- 目标 Id。根据不同的 conversationType,可能是用户 Id、讨论组 Id、群组 Id。notificationStatus
- 是否屏蔽。callback
- 设置状态的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
setConversationNotificationStatus
void )>setConversationNotificationStatus(ConversationIdentifier conversationIdentifier, ConversationNotificationStatus notificationStatus, ResultCallback<ConversationNotificationStatus> callback)
设置会话消息提醒状态。
- Parameters:
conversationIdentifier
- 会话标识。notificationStatus
- 是否屏蔽。callback
- 设置状态的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
insertOutgoingMessage
void )>insertOutgoingMessage(ConversationType type, String targetId, SentStatus sentStatus, MessageContent content, ResultCallback<Message> resultCallback)
向本地会话中插入一条消息,方向为发送。这条消息只是插入本地会话,不会实际发送给服务器和对方。 插入消息需为入库消息,即 ISPERSISTED,否者会回调 PARAMETER_ERROR
- Parameters:
type
- 会话类型。targetId
- 目标会话Id。比如私人会话时,是对方的id; 群组会话时,是群id; 讨论组会话时,则为该讨论,组的id.sentStatus
- 接收状态 @see Message.content
- 消息内容。如TextMessageImageMessage等。resultCallback
- 获得消息发送实体的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
insertOutgoingMessage
void )>insertOutgoingMessage(ConversationType type, String targetId, SentStatus sentStatus, MessageContent content, long time, ResultCallback<Message> resultCallback)
-
insertOutgoingMessage
void )>insertOutgoingMessage(ConversationIdentifier conversationIdentifier, SentStatus sentStatus, MessageContent content, long time, ResultCallback<Message> resultCallback)
向本地会话中插入一条消息,方向为发送。这条消息只是插入本地会话,不会实际发送给服务器和对方。 插入消息需为入库消息,即 ISPERSISTED,否者会回调 PARAMETER_ERROR
- Parameters:
conversationIdentifier
- 会话标识。sentStatus
- 发送状态 @see Message.content
- 消息内容。如TextMessageImageMessage等。time
- 插入消息所要模拟的发送时间。resultCallback
- 获得消息发送实体的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
insertIncomingMessage
void )>insertIncomingMessage(ConversationType type, String targetId, String senderId, ReceivedStatus receivedStatus, MessageContent content, ResultCallback<Message> resultCallback)
-
insertIncomingMessage
void )>insertIncomingMessage(ConversationType type, String targetId, String senderId, ReceivedStatus receivedStatus, MessageContent content, long time, ResultCallback<Message> resultCallback)
-
deleteMessages
void )>deleteMessages(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
清除指定会话的消息。
此接口会删除指定会话中数据库的所有消息,同时,会清理数据库空间。 如果数据库特别大,超过几百 M,调用该接口会有少许耗时。
- Parameters:
conversationType
- 要删除的消息 Id 数组。targetId
- 目标 Id。根据不同的 conversationType,可能是用户 Id、讨论组 Id、群组 Id。callback
- 是否删除成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
deleteMessages
void )>deleteMessages(ConversationType conversationType, String targetId, Array<int> messageIds, ResultCallback<Boolean> callback)
删除会话里的一条或多条消息。
- Parameters:
conversationType
- 会话类型targetId
- 会话 IdmessageIds
- 待删除的消息 Id 数组。callback
- 删除操作的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
deleteRemoteMessages
void deleteRemoteMessages(ConversationType conversationType, String targetId, Array<Message> messages, OperationCallback callback)
删除指定的一条或者一组消息。会同时删除本地和远端消息。
请注意,此方法会删除远端消息,请慎重使用
5.6.9版本以下不支持超级群会话类型,从 5.6.9 版本开始支持超级群会话类型
- Parameters:
conversationType
- 会话类型。暂时不支持聊天室targetId
- 目标 Id。根据不同的 conversationType,可能是用户 Id、客服 Id。messages
- 要删除的消息数组, 数组大小不能超过100条。callback
- 是否删除成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
deleteRemoteMessages
void deleteRemoteMessages(ConversationIdentifier identifier, Array<Message> messages, OperationCallback callback)
删除指定的一条或者一组消息。会同时删除本地和远端消息。
请注意,此方法会删除远端消息,请慎重使用
5.6.9版本以下不支持超级群会话类型,从 5.6.9 版本开始支持超级群会话类型
- Parameters:
identifier
- 会话标识。会话类型不支持聊天室。messages
- 要删除的消息数组, 数组大小不能超过100条。callback
- 是否删除成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。- Since:
5.6.9
-
disconnect
void disconnect()
断开连接(断开后继续接收 Push 消息)。
-
downloadMedia
void downloadMedia(ConversationType conversationType, String targetId, MediaType mediaType, String imageUrl, DownloadMediaCallback callback)
下载文件。
用来获取媒体原文件时调用。如果本地缓存中包含此文件,则从本地缓存中直接获取,否则将从服务器端下载。
- Parameters:
conversationType
- 会话类型。targetId
- 目标 Id。根据不同的 conversationType,可能是用户 Id、讨论组 Id、群组 Id 或聊天室 Id。mediaType
- 文件类型。imageUrl
- 文件的 URL 地址。callback
- 下载文件的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
downloadMediaFile
void downloadMediaFile(String uid, String fileUrl, String fileName, String path, IDownloadMediaFileCallback callback)
下载文件 支持断点续传
- Parameters:
uid
- 文件唯一标识fileUrl
- 文件下载地址fileName
- 文件名path
- 文件下载保存目录,如果是 targetVersion 29 为目标,由于访问权限原因,建议使用 context.callback
- 回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
cancelDownloadMediaMessage
void cancelDownloadMediaMessage(Message message, OperationCallback callback)
取消下载多媒体文件。
- Parameters:
message
- 包含多媒体文件的消息,即MessageContent为 FileMessage, ImageMessage 等。callback
- 取消下载多媒体文件时的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
clearConversations
void clearConversations(ResultCallback callback, Array<ConversationType> conversationTypes)
清空所有会话及会话内的消息,回调方式通知是否清空成功。
- Parameters:
callback
- 是否清空成功的回调。conversationTypes
- 会话类型。
-
downloadMediaMessage
void downloadMediaMessage(Message message, IDownloadMediaMessageCallback callback)
下载文件
用来获取媒体原文件时调用。如果本地缓存中包含此文件,则从本地缓存中直接获取,否则将从服务器端下载。
- Parameters:
message
- 文件消息。callback
- 下载文件的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
logout
void logout()
注销当前登录,执行该方法后不会再收到 push 消息。
-
setMessageInterceptor
void setMessageInterceptor(MessageInterceptor messageInterceptor)
设置接收消息时的拦截器
- Parameters:
messageInterceptor
- 拦截器
-
supportResumeBrokenTransfer
void )>supportResumeBrokenTransfer(String url, ResultCallback<Boolean> callback)
判断是否支持断点续传。
- Parameters:
url
- 文件 Urlcallback
- 回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
pauseDownloadMediaMessage
void pauseDownloadMediaMessage(Message message, OperationCallback callback)
暂停下载多媒体文件
- Parameters:
message
- 包含多媒体文件的消息,即MessageContent为 FileMessage, ImageMessage 等。callback
- 暂停下载多媒体文件时的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
refreshMessage
void refreshMessage(Message message)
通知会话页面刷新某条消息
-
getContext
Context getContext()
-
sendLocationMessage
void sendLocationMessage(Message message, String pushContent, String pushData, ISendMessageCallback sendMessageCallback)
发送地理位置消息。并同时更新界面。
发送前构造 Message 消息实体,消息实体中的 content 必须为 LocationMessage, 否则返回失败。
其中的缩略图地址 scheme 只支持 file:// 和 http:// 其他暂不支持。
- Parameters:
message
- 消息实体。pushContent
- 当下发 push 消息时,在通知栏里会显示这个字段。 如果发送的是自定义消息,该字段必须填写,否则无法收到 push 消息。 如果发送 sdk 中默认的消息类型,例如 RC:TxtMsg, RC:VcMsg, RC:ImgMsg,则不需要填写,默认已经指定。pushData
- push 附加信息。如果设置该字段,用户在收到 push 消息时,能通过 getPushData 方法获取。sendMessageCallback
- 发送消息的回调,参考 IRongCallback.
-
setMessageSentStatus
void )>setMessageSentStatus(Message message, ResultCallback<Boolean> callback)
根据消息 Message 设置消息状态,回调方式获取设置是否成功。
- Parameters:
message
- 消息实体。要设置的发送状态包含在 message 中callback
- 是否设置成功的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
handleBeforeSend
void handleBeforeSend(Message message)
发送消息之前的内部逻辑处理。
- Parameters:
message
- 待发送的消息
-
cancelSendMediaMessage
void cancelSendMediaMessage(Message message, OperationCallback callback)
取消发送多媒体文件。
- Parameters:
message
- 包含多媒体文件的消息,即MessageContent为 FileMessage, ImageMessage 等。callback
- 取消发送多媒体文件时的回调。该回调在主线程中执行,请避免在回调中执行耗时操作,防止 SDK 线程阻塞。
-
changeMessageReceivedStatus
void changeMessageReceivedStatus(int messageId, ConversationType conversationType, String targetId, ReceivedStatus status)
-
addOnReceiveMessageListener
void addOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
-
removeOnReceiveMessageListener
void removeOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
-
addAsyncOnReceiveMessageListener
void addAsyncOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
-
removeAsyncOnReceiveMessageListener
void removeAsyncOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
-
addSyncConversationReadStatusListener
void addSyncConversationReadStatusListener(SyncConversationReadStatusListener listener)
-
removeSyncConversationReadStatusListeners
void removeSyncConversationReadStatusListeners(SyncConversationReadStatusListener listener)
-
addConnectStatusListener
void addConnectStatusListener(ConnectCallback callback)
-
removeConnectStatusListener
void removeConnectStatusListener(ConnectCallback callback)
-
addConnectionStatusListener
void addConnectionStatusListener(ConnectionStatusListener listener)
设置连接状态变化的监听器。
当回调状态为TOKEN_INCORRECT, 需要获取正确的token, 并主动调用connect
- Parameters:
listener
- 连接状态变化的监听器。
-
removeConnectionStatusListener
void removeConnectionStatusListener(ConnectionStatusListener listener)
移除连接状态监听器
- Parameters:
listener
- 连接状态变化监听器
-
addConversationEventListener
void addConversationEventListener(ConversationEventListener listener)
-
removeConversationEventListener
void removeConversationEventListener(ConversationEventListener listener)
-
addMessageEventListener
void addMessageEventListener(MessageEventListener listener)
-
removeMessageEventListener
void removeMessageEventListener(MessageEventListener listener)
-
addConversationStatusListener
void addConversationStatusListener(ConversationStatusListener listener)
-
removeConversationStatusListener
void removeConversationStatusListener(ConversationStatusListener listener)
-
addOnRecallMessageListener
void addOnRecallMessageListener(OnRecallMessageListener listener)
-
removeOnRecallMessageListener
void removeOnRecallMessageListener(OnRecallMessageListener listener)
-
addReadReceiptListener
void addReadReceiptListener(ReadReceiptListener listener)
-
removeReadReceiptListener
void removeReadReceiptListener(ReadReceiptListener listener)
-
addTypingStatusListener
void addTypingStatusListener(TypingStatusListener listener)
-
removeTypingStatusListener
void removeTypingStatusListener(TypingStatusListener listener)
-
addCancelSendMediaMessageListener
void )>addCancelSendMediaMessageListener(ResultCallback<Message> listener)
-
removeCancelSendMediaMessageListener
void )>removeCancelSendMediaMessageListener(ResultCallback<Message> listener)
-
-
-
-