# IMCenter

public class IMCenter

## Types

FilterSentListener
Link copied to clipboard
public interface FilterSentListener
VoiceMessageType
Link copied to clipboard
public enum VoiceMessageType
语音消息类型

## Properties

kitFragmentFactory
Link copied to clipboard
public static KitFragmentFactory kitFragmentFactory

## Functions

addAsyncOnReceiveMessageListener
Link copied to clipboard
public void addAsyncOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
addCancelSendMediaMessageListener
Link copied to clipboard
public void addCancelSendMediaMessageListener(ResultCallback<Message> listener)
addConnectionStatusListener
Link copied to clipboard
public void addConnectionStatusListener(ConnectionStatusListener listener)
设置连接状态变化的监听器。 当回调状态为TOKEN_INCORRECT, 需要获取正确的token, 并主动调用connect
addConnectStatusListener
Link copied to clipboard
public void addConnectStatusListener(ConnectCallback callback)
addConversationEventListener
Link copied to clipboard
public void addConversationEventListener(ConversationEventListener listener)
addConversationStatusListener
Link copied to clipboard
public void addConversationStatusListener(ConversationStatusListener listener)
addFriendEventListener
Link copied to clipboard
public void addFriendEventListener(FriendEventListener listener)
添加好友事件监听器
addGroupEventListener
Link copied to clipboard
public void addGroupEventListener(GroupEventListener listener)
添加群组事件监听器
addMediaListener
Link copied to clipboard
public void addMediaListener(String uid, IDownloadMediaFileCallback listener)
addMessageEventListener
Link copied to clipboard
public void addMessageEventListener(MessageEventListener listener)
addOnGroupAndUserEventListener
Link copied to clipboard
public void addOnGroupAndUserEventListener(OnGroupAndUserEventListener listener)
添加群组和用户信息事件监听
addOnRecallMessageListener
Link copied to clipboard
public void addOnRecallMessageListener(OnRecallMessageListener listener)
addOnReceiveMessageListener
Link copied to clipboard
public void addOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
addReadReceiptListener
Link copied to clipboard
public void addReadReceiptListener(ReadReceiptListener listener)
addSubscribeEventListener
Link copied to clipboard
public void addSubscribeEventListener(OnSubscribeEventListener listener)
添加订阅事件监听器
addSyncConversationReadStatusListener
Link copied to clipboard
public void addSyncConversationReadStatusListener(SyncConversationReadStatusListener listener)
addTypingStatusListener
Link copied to clipboard
public void addTypingStatusListener(TypingStatusListener listener)
cancelDownloadMediaMessage
Link copied to clipboard
public void cancelDownloadMediaMessage(Message message, OperationCallback callback)
取消下载多媒体文件。
cancelSendMediaMessage
Link copied to clipboard
public void cancelSendMediaMessage(Message message, OperationCallback callback)
取消发送多媒体文件。
changeMessageReceivedStatus
Link copied to clipboard
public void changeMessageReceivedStatus(int messageId, ConversationType conversationType, String targetId, ReceivedStatus status)
cleanHistoryMessages
Link copied to clipboard
public void cleanHistoryMessages(ConversationIdentifier conversationIdentifier, long recordTime, boolean cleanRemote, OperationCallback callback)
public void cleanHistoryMessages(ConversationType conversationType, String targetId, long recordTime, boolean cleanRemote, OperationCallback callback)
删除指定时间戳之前的消息，可选择是否同时删除服务器端消息 此方法可从服务器端清除历史消息，但是必须先开通历史消息云存储功能。 根据会话类型和会话 id 清除某一会话指定时间戳之前的本地数据库消息（服务端历史消息）， 清除成功后只能从本地数据库（服务端）获取到该时间戳之后的历史消息。
clearConversations
Link copied to clipboard
public void clearConversations(ResultCallback callback, Array<ConversationType> conversationTypes)
清空所有会话及会话内的消息，回调方式通知是否清空成功。
clearMessages
Link copied to clipboard
public void clearMessages(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
根据会话类型，清空某一会话的所有聊天消息记录,回调方式获取清空是否成功。
clearMessagesUnreadStatus
Link copied to clipboard
public void clearMessagesUnreadStatus(ConversationIdentifier conversationIdentifier, ResultCallback<Boolean> callback)
public void clearMessagesUnreadStatus(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
清除某会话的消息未读状态
clearTextMessageDraft
Link copied to clipboard
public void clearTextMessageDraft(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
清除某一会话的文字消息草稿，回调方式获取清除是否成功。
connect
Link copied to clipboard
public void connect(String token, ConnectCallback connectCallback)
public void connect(String token, int timeLimit, ConnectCallback connectCallback)
连接服务器，在整个应用程序全局，只需要调用一次。 调用该接口，SDK 会在 timeLimit 秒内尝试重连，直到出现下面三种情况之一： 第一、连接成功，回调 onSuccess(userId)。 第二、超时，回调 onError(RC_CONNECT_TIMEOUT)，并不再重连。 第三、出现 SDK 无法处理的错误，回调 onError(errorCode)（如 token 非法），并不再重连。 连接成功后，SDK 将接管所有的重连处理。当因为网络原因断线的情况下，SDK 会不停重连直到连接成功为止，不需要您做额外的连接操作。
deleteMessages
Link copied to clipboard
public void deleteMessages(ConversationType conversationType, String targetId, ResultCallback<Boolean> callback)
清除指定会话的消息。 此接口会删除指定会话中数据库的所有消息，同时，会清理数据库空间。 如果数据库特别大，超过几百 M，调用该接口会有少许耗时。
public void deleteMessages(ConversationType conversationType, String targetId, Array<int> messageIds, ResultCallback<Boolean> callback)
删除会话里的一条或多条消息。
deleteRemoteMessages
Link copied to clipboard
public void deleteRemoteMessages(ConversationIdentifier identifier, Array<Message> messages, OperationCallback callback)
public void deleteRemoteMessages(ConversationType conversationType, String targetId, Array<Message> messages, OperationCallback callback)
删除指定的一条或者一组消息。会同时删除本地和远端消息。 请注意，此方法会删除远端消息，请慎重使用 5.6.9版本以下不支持超级群会话类型，从 5.6.
disconnect
Link copied to clipboard
public void disconnect()
断开连接(断开后继续接收 Push 消息)。
downloadMedia
Link copied to clipboard
public void downloadMedia(ConversationType conversationType, String targetId, MediaType mediaType, String imageUrl, DownloadMediaCallback callback)
下载文件。 用来获取媒体原文件时调用。如果本地缓存中包含此文件，则从本地缓存中直接获取，否则将从服务器端下载。
downloadMediaFile
Link copied to clipboard
public void downloadMediaFile(String uid, String fileUrl, String fileName, String path, IDownloadMediaFileCallback callback)
下载文件 支持断点续传
downloadMediaMessage
Link copied to clipboard
public void downloadMediaMessage(Message message, IDownloadMediaMessageCallback callback)
下载文件 用来获取媒体原文件时调用。如果本地缓存中包含此文件，则从本地缓存中直接获取，否则将从服务器端下载。
getContext
Link copied to clipboard
public Context getContext()
getCurrentConnectionStatus
Link copied to clipboard
public ConnectionStatus getCurrentConnectionStatus()
getInstance
Link copied to clipboard
public static IMCenter getInstance()
getKitFragmentFactory
Link copied to clipboard
public static KitFragmentFactory getKitFragmentFactory()
获取创建生成的Fragment的工厂
handleBeforeSend
Link copied to clipboard
public void handleBeforeSend(Message message)
发送消息之前的内部逻辑处理。
init
Link copied to clipboard
public static void init(Application application, String appKey, InitOption option)
public static void init(Application application, String appKey, boolean isEnablePush)
public static void init(Application application, String appKey, boolean isEnablePush, Boolean isMainProcess)
初始化 SDK，在整个应用程序全局，只需要调用一次。
insertIncomingMessage
Link copied to clipboard
public void insertIncomingMessage(ConversationType type, String targetId, String senderId, ReceivedStatus receivedStatus, MessageContent content, ResultCallback<Message> resultCallback)
public void insertIncomingMessage(ConversationType type, String targetId, String senderId, ReceivedStatus receivedStatus, MessageContent content, long time, ResultCallback<Message> resultCallback)
insertOutgoingMessage
Link copied to clipboard
public void insertOutgoingMessage(ConversationType type, String targetId, SentStatus sentStatus, MessageContent content, ResultCallback<Message> resultCallback)
public void insertOutgoingMessage(ConversationIdentifier conversationIdentifier, SentStatus sentStatus, MessageContent content, long time, ResultCallback<Message> resultCallback)
向本地会话中插入一条消息，方向为发送。这条消息只是插入本地会话，不会实际发送给服务器和对方。 插入消息需为入库消息，即 ISPERSISTED，否者会回调 PARAMETER_ERROR
public void insertOutgoingMessage(ConversationType type, String targetId, SentStatus sentStatus, MessageContent content, long time, ResultCallback<Message> resultCallback)
isInitialized
Link copied to clipboard
public boolean isInitialized()
返回 SDK 是否已经初始化。
logout
Link copied to clipboard
public void logout()
注销当前登录，执行该方法后不会再收到 push 消息。
pauseDownloadMediaMessage
Link copied to clipboard
public void pauseDownloadMediaMessage(Message message, OperationCallback callback)
暂停下载多媒体文件
recallMessage
Link copied to clipboard
public void recallMessage(Message message, String pushContent, ResultCallback callback)
撤回消息
refreshMessage
Link copied to clipboard
public void refreshMessage(Message message)
通知会话页面刷新某条消息
removeAsyncOnReceiveMessageListener
Link copied to clipboard
public void removeAsyncOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
removeCancelSendMediaMessageListener
Link copied to clipboard
public void removeCancelSendMediaMessageListener(ResultCallback<Message> listener)
removeConnectionStatusListener
Link copied to clipboard
public void removeConnectionStatusListener(ConnectionStatusListener listener)
移除连接状态监听器
removeConnectStatusListener
Link copied to clipboard
public void removeConnectStatusListener(ConnectCallback callback)
removeConversation
Link copied to clipboard
public void removeConversation(ConversationType type, String targetId, ResultCallback<Boolean> callback)
从会话列表中移除某一会话，但是不删除会话内的消息。 如果此会话中有新的消息，该会话将重新在会话列表中显示，并显示最近的历史消息。
removeConversationEventListener
Link copied to clipboard
public void removeConversationEventListener(ConversationEventListener listener)
removeConversationStatusListener
Link copied to clipboard
public void removeConversationStatusListener(ConversationStatusListener listener)
removeFriendEventListener
Link copied to clipboard
public void removeFriendEventListener(FriendEventListener listener)
移除好友事件监听器
removeGroupEventListener
Link copied to clipboard
public void removeGroupEventListener(GroupEventListener listener)
移除群组事件监听器
removeMediaListener
Link copied to clipboard
public void removeMediaListener(String uid)
removeMessageEventListener
Link copied to clipboard
public void removeMessageEventListener(MessageEventListener listener)
removeOnGroupAndUserEventListener
Link copied to clipboard
public void removeOnGroupAndUserEventListener(OnGroupAndUserEventListener listener)
移除群组和用户信息事件监听
removeOnRecallMessageListener
Link copied to clipboard
public void removeOnRecallMessageListener(OnRecallMessageListener listener)
removeOnReceiveMessageListener
Link copied to clipboard
public void removeOnReceiveMessageListener(OnReceiveMessageWrapperListener listener)
removeReadReceiptListener
Link copied to clipboard
public void removeReadReceiptListener(ReadReceiptListener listener)
removeSubscribeEventListener
Link copied to clipboard
public void removeSubscribeEventListener(OnSubscribeEventListener listener)
移除订阅事件监听器
removeSyncConversationReadStatusListeners
Link copied to clipboard
public void removeSyncConversationReadStatusListeners(SyncConversationReadStatusListener listener)
removeTypingStatusListener
Link copied to clipboard
public void removeTypingStatusListener(TypingStatusListener listener)
saveTextMessageDraft
Link copied to clipboard
public void saveTextMessageDraft(ConversationIdentifier conversationIdentifier, String content, ResultCallback<Boolean> callback)
public void saveTextMessageDraft(ConversationType conversationType, String targetId, String content, ResultCallback<Boolean> callback)
保存文字消息草稿，回调方式获取保存是否成功。
sendDirectionalMediaMessage
Link copied to clipboard
public void sendDirectionalMediaMessage(Message message, Array<String> userIds, String pushContent, String pushData, ISendMediaMessageCallback callback)
发送定向多媒体消息 向会话中特定的某些用户发送消息，会话中其他用户将不会收到此消息。 发送前构造 Message 消息实体，消息实体中的 content 必须为多媒体消息，如 ImageMessage或者其他继承自 MediaMessageContent 的消息 从 5.6.
sendDirectionalMessage
Link copied to clipboard
public void sendDirectionalMessage(Message message, Array<String> userIds, String pushContent, String pushData, ISendMessageCallback callback)
public void sendDirectionalMessage(ConversationType type, String targetId, MessageContent content, Array<String> userIds, String pushContent, String pushData, ISendMessageCallback callback)
发送定向消息。向会话中特定的某些用户发送消息，会话中其他用户将不会收到此消息。 通过 IRongCallback.
sendLocationMessage
Link copied to clipboard
public void sendLocationMessage(Message message, String pushContent, String pushData, ISendMessageCallback sendMessageCallback)
发送地理位置消息。并同时更新界面。 发送前构造 Message 消息实体，消息实体中的 content 必须为 LocationMessage, 否则返回失败。 其中的缩略图地址 scheme 只支持 file:// 和 http:// 其他暂不支持。
sendMediaMessage
Link copied to clipboard
public void sendMediaMessage(Message message, String pushContent, String pushData, ISendMediaMessageCallback callback)
public void sendMediaMessage(Message message, String pushContent, String pushData, SendMessageOption option, ISendMediaMessageCallback callback)
发送消息。 通过 IRongCallback.
public void sendMediaMessage(Message message, String pushContent, String pushData, ISendMediaMessageCallbackWithUploader callback)
public void sendMediaMessage(Message message, String pushContent, String pushData, SendMessageOption option, ISendMediaMessageCallbackWithUploader callback)
sendMessage
Link copied to clipboard
public void sendMessage(Message message, String pushContent, String pushData, ISendMessageCallback callback)
public void sendMessage(Message message, String pushContent, String pushData, SendMessageOption option, ISendMessageCallback callback)
发送消息。 通过 IRongCallback.
public void sendMessage(ConversationType type, String targetId, MessageContent content, String pushContent, String pushData, ISendMessageCallback callback)
根据会话类型，发送消息。 通过 IRongCallback.
sendReadReceiptMessage
Link copied to clipboard
public void sendReadReceiptMessage(ConversationType conversationType, String targetId, long timestamp, ISendMessageCallback callback)
发送已读回执，该方法会触发刷新消息未读数 通过 IRongCallback.
setConversationClickListener
Link copied to clipboard
public static void setConversationClickListener(ConversationClickListener listener)
设置会话界面操作的监听器。
setConversationListBehaviorListener
Link copied to clipboard
public static void setConversationListBehaviorListener(ConversationListBehaviorListener listener)
设置会话列表界面操作的监听器。
setConversationNotificationStatus
Link copied to clipboard
public void setConversationNotificationStatus(ConversationIdentifier conversationIdentifier, ConversationNotificationStatus notificationStatus, ResultCallback<ConversationNotificationStatus> callback)
public void setConversationNotificationStatus(ConversationType conversationType, String targetId, ConversationNotificationStatus notificationStatus, ResultCallback<ConversationNotificationStatus> callback)
设置会话消息提醒状态。
setConversationToTop
Link copied to clipboard
public void setConversationToTop(ConversationIdentifier conversationIdentifier, boolean isTop, ResultCallback<Boolean> callback)
@Deprecated()
public void setConversationToTop(ConversationIdentifier conversationIdentifier, boolean isTop, boolean needCreate, ResultCallback<Boolean> callback)
@Deprecated()
public void setConversationToTop(ConversationType type, String targetId, boolean isTop, boolean needCreate, ResultCallback<Boolean> callback)
public void setConversationToTop(ConversationIdentifier conversationIdentifier, boolean isTop, boolean needCreate, boolean needUpdateTime, ResultCallback<Boolean> callback)
设置某一会话为置顶或者取消置顶，回调方式获取设置是否成功。
setFriendInfo
Link copied to clipboard
public void setFriendInfo(String userId, String remark, Map<String, String> extProfile, ExamineOperationCallback callback)
@Deprecated()
public void setFriendInfo(String userId, String remark, Map<String, String> extProfile, OperationCallback callback)
设置好友信息
setGroupMemberInfo
Link copied to clipboard
public void setGroupMemberInfo(String groupId, String userId, String nickname, String extra, ExamineOperationCallback callback)
设置群组成员信息
@Deprecated()
public void setGroupMemberInfo(String groupId, String userId, String nickname, String extra, OperationCallback callback)
设置群组信息
setGroupRemark
Link copied to clipboard
public void setGroupRemark(String groupId, String remark, OperationCallback callback)
设置群组备注
setKitFragmentFactory
Link copied to clipboard
public static void setKitFragmentFactory(KitFragmentFactory kitFragmentFactory)
设置创建生成的Fragment的工厂
setMessageInterceptor
Link copied to clipboard
public void setMessageInterceptor(MessageInterceptor messageInterceptor)
设置接收消息时的拦截器
setMessageSentStatus
Link copied to clipboard
public void setMessageSentStatus(Message message, ResultCallback<Boolean> callback)
根据消息 Message 设置消息状态，回调方式获取设置是否成功。
supportResumeBrokenTransfer
Link copied to clipboard
public void supportResumeBrokenTransfer(String url, ResultCallback<Boolean> callback)
判断是否支持断点续传。
syncConversationReadStatus
Link copied to clipboard
public void syncConversationReadStatus(ConversationIdentifier conversationIdentifier, long timestamp, OperationCallback callback)
public void syncConversationReadStatus(ConversationType type, String targetId, long timestamp, OperationCallback callback)
同步会话阅读状态。
updateGroupInfo
Link copied to clipboard
public void updateGroupInfo(GroupInfo groupInfo, ExamineOperationCallback callback)
设置群组资料
@Deprecated()
public void updateGroupInfo(GroupInfo groupInfo, OperationCallbackEx<String> callback)
设置消息接收状态
updateMyUserProfile
Link copied to clipboard
@Deprecated()
public void updateMyUserProfile(UserProfile userProfile, UpdateUserProfileCallback callback)
public void updateMyUserProfile(UserProfile userProfile, UpdateUserProfileEnhancedCallback callback)
更新我的用户信息