hyphenate_SDK4.0 4.6.0
hyphenate java IM SDK
Public 成员函数 | Protected 成员函数 | 所有成员列表
com.hyphenate.chat.EMChatManager类 参考

Public 成员函数

void sendMessage (final EMMessage msg)
 
void ackConversationRead (String conversationId) throws HyphenateException
 
void ackMessageRead (String to, String messageId) throws HyphenateException
 
void ackGroupMessageRead (String to, String messageId, String ext) throws HyphenateException
 
void recallMessage (EMMessage message) throws HyphenateException
 
void asyncRecallMessage (final EMMessage message, final EMCallBack callback)
 
void recallMessage (EMMessage message, String ext) throws HyphenateException
 
void asyncRecallMessage (final EMMessage message, String ext, final EMCallBack callback)
 
EMMessage getMessage (String messageId)
 
EMConversation getConversation (String id)
 
EMConversation getConversation (String id, EMConversationType type)
 
EMConversation getConversation (String username, EMConversationType type, boolean createIfNotExists)
 
EMConversation getConversation (String username, EMConversationType type, boolean createIfNotExists, boolean isChatThread)
 
boolean markAllConversationsAsRead ()
 
int getUnreadMessageCount ()
 
void saveMessage (EMMessage message)
 
boolean updateMessage (EMMessage message)
 
void asyncModifyMessage (String messageId, EMMessageBody messageBodyModified, final EMValueCallBack< EMMessage > callBack)
 
void downloadAttachment (final EMMessage msg)
 
void downloadThumbnail (final EMMessage msg)
 
void downloadAndParseCombineMessage (EMMessage message, EMValueCallBack< List< EMMessage > > callback)
 
synchronized void importMessages (List< EMMessage > msgs)
 
List< EMConversationgetConversationsByType (EMConversationType type)
 
Map< String, EMConversationgetAllConversations ()
 
List< EMConversationgetAllConversationsBySort ()
 
void asyncFilterConversationsFromDB (EMCustomConversationFilter filter, boolean cleanConversationsCache, EMValueCallBack< List< EMConversation > > callBack)
 
void cleanConversationsMemoryCache ()
 
Map< String, EMConversationfetchConversationsFromServer () throws HyphenateException
 
void asyncFetchConversationsFromServer (final EMValueCallBack< Map< String, EMConversation > > callBack)
 
void asyncFetchConversationsFromServer (int pageNum, int pageSize, final EMValueCallBack< Map< String, EMConversation > > callBack)
 
void asyncFetchPinnedConversationsFromServer (final int limit, final String cursor, final EMValueCallBack< EMCursorResult< EMConversation > > callback)
 
void asyncFetchConversationsFromServer (final int limit, final String cursor, final EMValueCallBack< EMCursorResult< EMConversation > > callback)
 
void asyncPinConversation (final String conversationId, boolean isPinned, final EMCallBack callback)
 
void loadAllConversations ()
 
boolean deleteConversation (String username, boolean deleteMessages)
 
void deleteConversationFromServer (String username, EMConversationType type, boolean isDeleteServerMessages, EMCallBack deleteCallBack)
 
void addMessageListener (EMMessageListener listener)
 
void removeMessageListener (EMMessageListener listener)
 
void addConversationListener (EMConversationListener listener)
 
void removeConversationListener (EMConversationListener listener)
 
void setVoiceMessageListened (EMMessage message)
 
boolean updateParticipant (String from, String changeTo)
 
EMCursorResult< EMGroupReadAckfetchGroupReadAcks (String msgId, int pageSize, String startAckId) throws HyphenateException
 
void asyncFetchGroupReadAcks (final String msgId, final int pageSize, final String startAckId, final EMValueCallBack< EMCursorResult< EMGroupReadAck > > callBack)
 
EMCursorResult< EMMessagefetchHistoryMessages (String conversationId, EMConversationType type, int pageSize, String startMsgId) throws HyphenateException
 
EMCursorResult< EMMessagefetchHistoryMessages (String conversationId, EMConversationType type, int pageSize, String startMsgId, EMConversation.EMSearchDirection direction) throws HyphenateException
 
void asyncFetchHistoryMessage (final String conversationId, final EMConversationType type, final int pageSize, final String startMsgId, final EMValueCallBack< EMCursorResult< EMMessage > > callBack)
 
void asyncFetchHistoryMessage (final String conversationId, final EMConversationType type, final int pageSize, final String startMsgId, final EMConversation.EMSearchDirection direction, final EMValueCallBack< EMCursorResult< EMMessage > > callBack)
 
void asyncFetchHistoryMessages (String conversationId, EMConversationType type, int pageSize, String cursor, EMFetchMessageOption option, final EMValueCallBack< EMCursorResult< EMMessage > > callBack)
 
List< EMMessagesearchMsgFromDB (Type type, long timeStamp, int maxCount, String from, EMConversation.EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMConversation.EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMConversation.EMSearchDirection direction, EMConversation.EMMessageSearchScope searchScope)
 
void deleteMessagesBeforeTimestamp (long timeStamp, EMCallBack callback)
 
void asyncReportMessage (String msgId, String tag, String reportReason, EMCallBack callback)
 
void reportMessage (String msgId, String tag, String reportReason) throws HyphenateException
 
void fetchSupportLanguages (EMValueCallBack< List< EMLanguage > > callback)
 
void translateMessage (EMMessage message, List< String > languages, EMValueCallBack< EMMessage > callback)
 
void addReaction (final String messageId, final String reaction) throws HyphenateException
 
void asyncAddReaction (final String messageId, final String reaction, final EMCallBack callback)
 
void removeReaction (final String messageId, final String reaction) throws HyphenateException
 
void asyncRemoveReaction (final String messageId, final String reaction, final EMCallBack callback)
 
Map< String, List< EMMessageReaction > > getReactionList (final List< String > messageIdList, final EMMessage.ChatType chatType, final String groupId) throws HyphenateException
 
void asyncGetReactionList (final List< String > messageIdList, final EMMessage.ChatType chatType, final String groupId, final EMValueCallBack< Map< String, List< EMMessageReaction > > > callback)
 
EMCursorResult< EMMessageReactiongetReactionDetail (final String messageId, final String reaction, final String cursor, final int pageSize) throws HyphenateException
 
void asyncGetReactionDetail (final String messageId, final String reaction, final String cursor, final int pageSize, final EMValueCallBack< EMCursorResult< EMMessageReaction > > callback)
 
void asyncAddConversationMark (@NonNull List< String > conversationIds, @NonNull EMMarkType mark, EMCallBack callback)
 
void asyncRemoveConversationMark (@NonNull List< String > conversationIds, @NonNull EMMarkType mark, EMCallBack callback)
 
void asyncGetConversationsFromServerWithCursor (@NonNull String cursor, @NonNull EMConversationFilter filter, EMValueCallBack< EMCursorResult< EMConversation > > callback)
 
void asyncDeleteAllMsgsAndConversations (boolean clearSeverData, EMCallBack deleteCallBack)
 
void asyncPinMessage (@NonNull String messageId, EMCallBack callBack)
 
void asyncUnPinMessage (@NonNull String messageId, EMCallBack callBack)
 
void asyncGetPinnedMessagesFromServer (@NonNull String conversationId, EMValueCallBack< List< EMMessage > > callBack)
 

Protected 成员函数

void removeMessagesFromServer (String conversationId, EMConversationType type, List< String > msgIdList, EMCallBack callBack)
 
void removeMessagesFromServer (String conversationId, EMConversationType type, long beforeTimeStamp, EMCallBack callBack)
 

详细描述

聊天管理类,该类负责管理会话(加载,删除等)、发送消息、下载消息附件等。

发送文文本消息示例如下:

EMMessage message = EMMessage.createTxtSendMessage(content, toChatUsername);
EMClient.getInstance().chatManager().sendMessage(message);

成员函数说明

◆ ackConversationRead()

void com.hyphenate.chat.EMChatManager.ackConversationRead ( String  conversationId) throws HyphenateException

发送会话的已读回执,该方法只针对单聊会话。

该方法会通知服务器将此会话未读数设置为 0,消息发送方将会收到 EMConversationListener#onConversationRead(String, String) 回调。 在多端多设备登录下,接收方的其他设备也会收到该回调。

群消息已读回执,详见 ackGroupMessageRead(String, String, String)

参数
conversationId会话 ID。
异常
HyphenateException可能抛出以下异常:EMError#USER_NOT_LOGINEMError#SERVER_NOT_REACHABLEEMError#MESSAGE_INVALID 等,详见 EMError

◆ ackGroupMessageRead()

void com.hyphenate.chat.EMChatManager.ackGroupMessageRead ( String  to,
String  messageId,
String  ext 
) throws HyphenateException

发送群消息已读回执。

注意

设置了 EMOptions#setRequireAck(boolean)EMMessage#setIsNeedGroupAck(boolean) 后才能调用该方法。

发送单聊消息已读回执,详见 ackMessageRead(String, String)

会话已读回执,详见 ackConversationRead(String)

参数
to会话 ID。
messageId消息 ID。
ext扩展信息。用户通过定义关键字指定动作或命令。
异常
HyphenateException如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError

◆ ackMessageRead()

void com.hyphenate.chat.EMChatManager.ackMessageRead ( String  to,
String  messageId 
) throws HyphenateException

发送消息的已读回执。

该方法仅适用于单聊会话,仅在 EMOptions#setRequireAck(boolean)true 时生效。

发送群消息已读回执,详见 ackGroupMessageRead(String, String, String)

推荐进入聊天页面的时调用 ackConversationRead(String) ,其他情况下调用该方法以减少调用频率。

参数
to接收方的用户 ID。
messageId消息的 ID。
异常
HyphenateException如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError

◆ addConversationListener()

void com.hyphenate.chat.EMChatManager.addConversationListener ( EMConversationListener  listener)

注册会话监听器。

会话监听器可监听会话变化及会话已读回执。

在不需要会话监听器时,可调用 removeConversationListener(EMConversationListener) 方法移除。

参数
listener要添加的会话监听,详见 EMConversationListener

◆ addMessageListener()

void com.hyphenate.chat.EMChatManager.addMessageListener ( EMMessageListener  listener)

注册消息监听器。

接收到新消息等回调可以通过设置此方法进行监听。

在不需要消息监听器时,可调用 removeMessageListener(EMMessageListener) 方法将其移除。

参数
listener要注册的消息监听,详见 EMMessageListener

◆ addReaction()

void com.hyphenate.chat.EMChatManager.addReaction ( final String  messageId,
final String  reaction 
) throws HyphenateException

添加 Reaction。

同步方法。

参数
messageId消息 ID。
reaction要添加的消息 Reaction。
异常
HyphenateException如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError

◆ asyncAddConversationMark()

void com.hyphenate.chat.EMChatManager.asyncAddConversationMark ( @NonNull List< String >  conversationIds,
@NonNull EMMarkType  mark,
EMCallBack  callback 
)

标记会话。

调用该方法会同时为本地和服务器端的会话添加标记。

参数
conversationIds会话 ID 列表。
mark要添加的会话标记。
callback该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ asyncAddReaction()

void com.hyphenate.chat.EMChatManager.asyncAddReaction ( final String  messageId,
final String  reaction,
final EMCallBack  callback 
)

添加 Reaction。

异步方法。

参数
messageId消息 ID。
reaction要添加的消息 Reaction。
callback处理结果回调,失败会返回失败原因。详见 EMCallBack

◆ asyncDeleteAllMsgsAndConversations()

void com.hyphenate.chat.EMChatManager.asyncDeleteAllMsgsAndConversations ( boolean  clearSeverData,
EMCallBack  deleteCallBack 
)

清空所有会话及其消息。

异步方法。

参数
clearSeverData是否删除服务端所有会话及其消息:
  • YES:是。服务端的所有会话及其消息会被清除,当前用户无法再从服务端拉取消息和会话,其他用户不受影响。
  • (默认)NO:否。只清除本地所有会话及其消息,服务端的会话及其消息仍保留。
deleteCallBack该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ asyncFetchConversationsFromServer() [1/3]

void com.hyphenate.chat.EMChatManager.asyncFetchConversationsFromServer ( final EMValueCallBack< Map< String, EMConversation > >  callBack)

从服务器获取会话列表。

异步方法。

返回
当前用户的会话列表。
弃用:
已废弃。请用 asyncFetchConversationsFromServer(int, String, EMValueCallBack) 代替。

◆ asyncFetchConversationsFromServer() [2/3]

void com.hyphenate.chat.EMChatManager.asyncFetchConversationsFromServer ( final int  limit,
final String  cursor,
final EMValueCallBack< EMCursorResult< EMConversation > >  callback 
)

分页从服务器获取获取会话列表。

SDK 按照会话活跃时间(会话的最后一条消息的时间戳)倒序返回会话列表。

若会话中没有消息,则 SDK 按照会话创建时间的倒序返回会话列表。

参数
limit每页期望返回的会话数量。取值范围为 [1,50]。
cursor开始获取数据的游标位置。若获取数据时传 null 或者空字符串(""),SDK 从最新活跃的会话开始获取。
callback分页获取结果 EMCursorResult,包含用于下次获取数据的 cursor 以及会话列表。 如果是最后一页,cursor 返回结果为空字符串。

◆ asyncFetchConversationsFromServer() [3/3]

void com.hyphenate.chat.EMChatManager.asyncFetchConversationsFromServer ( int  pageNum,
int  pageSize,
final EMValueCallBack< Map< String, EMConversation > >  callBack 
)

从服务器分页获取会话列表。

异步方法。

参数
pageNum当前页码,从 1 开始。
pageSize每页获取的会话数量,取值范围为 [1,20]。
返回
当前用户的会话列表。
弃用:
已废弃。请用 asyncFetchConversationsFromServer(int, String, EMValueCallBack) 代替。

◆ asyncFetchGroupReadAcks()

void com.hyphenate.chat.EMChatManager.asyncFetchGroupReadAcks ( final String  msgId,
final int  pageSize,
final String  startAckId,
final EMValueCallBack< EMCursorResult< EMGroupReadAck > >  callBack 
)

从服务器分页获取群组消息已读回执详情。

发送群组消息回执,可调用 ackGroupMessageRead(String, String, String)

异步方法。

参数
msgId消息 ID。
pageSize每页获取的群消息已读回执数。取值范围为 [1,50]。
startAckId查询起始的已读回执 ID。该参数设置后,SDK 从指定的已读回执 ID 开始,按服务器接收已读回执的时间的逆序获取。 若该参数为空,SDK 从最新的已读回执开始按服务器接收回执时间的逆序获取。
callBack结果回调。

◆ asyncFetchHistoryMessage() [1/2]

void com.hyphenate.chat.EMChatManager.asyncFetchHistoryMessage ( final String  conversationId,
final EMConversationType  type,
final int  pageSize,
final String  startMsgId,
final EMConversation.EMSearchDirection  direction,
final EMValueCallBack< EMCursorResult< EMMessage > >  callBack 
)

从服务器按消息搜索方向分页获取指定会话的所有类型的历史消息。

异步方法。

参数
conversationId会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID。
type会话类型,详见 EMConversationType
pageSize每页期望获取的消息数。取值范围为 [1,50]。
startMsgId查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始,按消息搜索方向获取。 如果传入消息的 ID 为空,SDK 忽略该参数,按搜索方向查询消息。
  • directionUP,SDK 从最新消息开始,按照服务器接收消息时间的逆序获取;
  • directionDOWN,SDK 从最早消息开始,按照服务器接收消息时间的正序获取。
direction消息搜索方向。详见 EMConversation.EMSearchDirection
  • (默认)UP:按照消息中的时间戳的逆序查询;
    • DOWN:按照消息中的时间戳的正序查询;
callBack结果回调:
弃用:
已废弃。请用 asyncFetchHistoryMessages(String, EMConversationType, int, String, EMFetchMessageOption, EMValueCallBack) 代替。

◆ asyncFetchHistoryMessage() [2/2]

void com.hyphenate.chat.EMChatManager.asyncFetchHistoryMessage ( final String  conversationId,
final EMConversationType  type,
final int  pageSize,
final String  startMsgId,
final EMValueCallBack< EMCursorResult< EMMessage > >  callBack 
)

从服务器分页获取指定会话的所有类型的历史消息。

异步方法。

参数
conversationId会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID。
type会话类型,详见 EMConversationType
pageSize每页期望获取的消息条数。取值范围为 [1,50]。
startMsgId查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始,按服务器接收消息的时间的逆序获取。 若该参数为空,SDK 从最新的消息开始,按服务器接收消息的时间的逆序获取。
callBack结果回调,成功则执行 EMValueCallBack#onSuccess(Object),返回消息列表(不包含查询起始 ID 的消息)和下次查询的 cursor; 失败则执行 EMValueCallBack#onError(int, String)
弃用:
已废弃。请用 asyncFetchHistoryMessages(String, EMConversationType, int, String, EMFetchMessageOption, EMValueCallBack) 代替。

◆ asyncFetchHistoryMessages()

void com.hyphenate.chat.EMChatManager.asyncFetchHistoryMessages ( String  conversationId,
EMConversationType  type,
int  pageSize,
String  cursor,
EMFetchMessageOption  option,
final EMValueCallBack< EMCursorResult< EMMessage > >  callBack 
)

/**

根据消息拉取参数配置类(EMFetchMessageOption)从服务器分页获取指定会话的历史消息。

异步方法。

参数
conversationId会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID。
  • 聊天室:聊天室 ID。
type会话类型, 详见 EMConversationType
pageSize每页期望获取的消息条数。取值范围为 [1,50]。
cursor查询的起始游标位置。
option查询历史消息的参数配置类,详见 EMFetchMessageOption
返回
查询到的消息列表和下次查询的 cursor。
参数
callBack结果回调:

◆ asyncFetchPinnedConversationsFromServer()

void com.hyphenate.chat.EMChatManager.asyncFetchPinnedConversationsFromServer ( final int  limit,
final String  cursor,
final EMValueCallBack< EMCursorResult< EMConversation > >  callback 
)

分页从服务器获取置顶会话。

SDK 按照会话置顶时间倒序返回。

参数
limit每页返回的会话数。取值范围为 [1,50]。
cursor开始获取数据的游标位置。若获取数据时传 null 或者空字符串(""),SDK 从最新置顶的会话开始查询。
callback分页获取结果 EMCursorResult,包含用于下次获取数据的 cursor 以及置顶的会话列表。 如果是最后一页,cursor 返回结果为空字符串。

◆ asyncFilterConversationsFromDB()

void com.hyphenate.chat.EMChatManager.asyncFilterConversationsFromDB ( EMCustomConversationFilter  filter,
boolean  cleanConversationsCache,
EMValueCallBack< List< EMConversation > >  callBack 
)

根据过滤器获取本地所有会话。

调用该接口时,SDK 会根据过滤条件从本地数据库获取会话。

异步方法。

参数
filter过滤器,详见 EMCustomConversationFilter。若要获取全部会话,传入 null 即可。
cleanConversationsCache是否清空内存缓存的会话。
callBack结果回调,成功时回调 EMValueCallBack#onSuccess(Object),返回过滤后的会话列表。

◆ asyncGetConversationsFromServerWithCursor()

void com.hyphenate.chat.EMChatManager.asyncGetConversationsFromServerWithCursor ( @NonNull String  cursor,
@NonNull EMConversationFilter  filter,
EMValueCallBack< EMCursorResult< EMConversation > >  callback 
)

根据会话过滤类从服务器分页查询会话列表。

参数
cursor查询的开始位置。若传入空字符串,SDK 从最新标记操作的会话开始获取。
filter会话查询选项,包括会话标记和每页获取的会话条数。
callback该方法完成的回调,返回会话列表和用于下一次获取数据的 cursor。当 cursor 为 空字符串时,表示已获取全部数据。

◆ asyncGetPinnedMessagesFromServer()

void com.hyphenate.chat.EMChatManager.asyncGetPinnedMessagesFromServer ( @NonNull String  conversationId,
EMValueCallBack< List< EMMessage > >  callBack 
)

从服务端获取置顶消息。

该方法为异步方法。

参数
conversationId会话 ID。
callBack该方法完成调用的回调。如果该方法成功,会包含所有置顶的消息。如果该方法调用失败,会包含调用失败的原因。

◆ asyncGetReactionDetail()

void com.hyphenate.chat.EMChatManager.asyncGetReactionDetail ( final String  messageId,
final String  reaction,
final String  cursor,
final int  pageSize,
final EMValueCallBack< EMCursorResult< EMMessageReaction > >  callback 
)

获取 Reaction 详细信息。

异步方法。

参数
messageId消息 ID。
reaction消息 Reaction。
cursor查询的起始游标位置。
pageSize每页期望获取的 Reaction 数。
callback处理结果回调,包含 cursor 和 EMMessageReaction 列表(仅使用该列表第一个数据即可)。

◆ asyncGetReactionList()

void com.hyphenate.chat.EMChatManager.asyncGetReactionList ( final List< String >  messageIdList,
final EMMessage.ChatType  chatType,
final String  groupId,
final EMValueCallBack< Map< String, List< EMMessageReaction > > >  callback 
)

获取 Reaction 列表。

异步方法。

参数
messageIdList消息 ID。
chatType会话类型,仅支持单聊(EMMessage.ChatType#Chat )和群聊(EMMessage.ChatType#GroupChat)。
groupId群组 ID,该参数只对群聊生效。
callback处理结果回调,包含消息 ID 对应的 Reaction 列表(EMMessageReaction 的用户列表 UserList 为概要数据,只包含前三个用户信息)。

◆ asyncModifyMessage()

void com.hyphenate.chat.EMChatManager.asyncModifyMessage ( String  messageId,
EMMessageBody  messageBodyModified,
final EMValueCallBack< EMMessage callBack 
)

修改消息内容。

调用该方法修改消息内容后,本地和服务端的消息均会修改。

调用该方法只能修改单聊和群聊中的文本消息,不能修改聊天室消息。

多设备和该消息的接收方可通过 EMMessageListener#onMessageContentChanged(EMMessage, String, long) 回调监听消息是否有变更。

参数
messageId消息 ID。
messageBodyModified内容修改后的消息体。
callBack消息修改是否成功的回调。EMValueCallBack 类的对象,详见 EMValueCallBack,包含已修改的消息对象。

◆ asyncPinConversation()

void com.hyphenate.chat.EMChatManager.asyncPinConversation ( final String  conversationId,
boolean  isPinned,
final EMCallBack  callback 
)

设置是否置顶会话。

参数
conversationId会话 ID。
isPinned是否置顶会话:
  • true:置顶;
  • false: 取消置顶。
    参数
    callback设置会话置顶状态的结果回调。

◆ asyncPinMessage()

void com.hyphenate.chat.EMChatManager.asyncPinMessage ( @NonNull String  messageId,
EMCallBack  callBack 
)

置顶消息。

该方法为异步方法。

参数
messageId消息 ID。
callBack该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ asyncRecallMessage() [1/2]

void com.hyphenate.chat.EMChatManager.asyncRecallMessage ( final EMMessage  message,
final EMCallBack  callback 
)

撤回发送成功的消息。

异步方法。

参数
message消息对象。
callbackEMCallBack 类的对象,详见 EMCallBack

◆ asyncRecallMessage() [2/2]

void com.hyphenate.chat.EMChatManager.asyncRecallMessage ( final EMMessage  message,
String  ext,
final EMCallBack  callback 
)

撤回发送成功的消息。

异步方法。

参数
message消息对象。
ext扩展信息
callbackEMCallBack 类的对象,详见 EMCallBack

◆ asyncRemoveConversationMark()

void com.hyphenate.chat.EMChatManager.asyncRemoveConversationMark ( @NonNull List< String >  conversationIds,
@NonNull EMMarkType  mark,
EMCallBack  callback 
)

取消标记会话。

调用该方法会同时为本地和服务器端的会话添加标记。

参数
conversationIds会话 ID 列表。
mark要移除的会话标记。
callback该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ asyncRemoveReaction()

void com.hyphenate.chat.EMChatManager.asyncRemoveReaction ( final String  messageId,
final String  reaction,
final EMCallBack  callback 
)

删除 Reaction。

异步方法。

参数
messageId消息 ID。
reaction要删除的 Reaction。
callback处理结果回调,详见 EMCallBack

◆ asyncReportMessage()

void com.hyphenate.chat.EMChatManager.asyncReportMessage ( String  msgId,
String  tag,
String  reportReason,
EMCallBack  callback 
)

举报非法消息。

异步方法。

参数
msgId要举报的消息 ID。
tag非法消息的标签。你需要填写自定义标签,例如涉政广告
reportReason举报原因。你需要自行填写举报原因。
callback结果回调,详见 EMCallBack

◆ asyncUnPinMessage()

void com.hyphenate.chat.EMChatManager.asyncUnPinMessage ( @NonNull String  messageId,
EMCallBack  callBack 
)

取消置顶消息。

该方法为异步方法。

参数
messageId消息 ID。
callBack该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ cleanConversationsMemoryCache()

void com.hyphenate.chat.EMChatManager.cleanConversationsMemoryCache ( )

清除本地内存中的所有会话释放内存。

注意:释放内存后,通过 getAllConversations()getAllConversationsBySort() 从内存里获取到的会话数可能为 0。通过getUnreadMessageCount()获取到的未读消息数可能为 0。

若需要获取所有会话和未读数,需要先调用 loadAllConversations()或者 asyncFilterConversationsFromDB(EMCustomConversationFilter, boolean, EMValueCallBack) 从数据库重新加载会话到内存里。

◆ deleteConversation()

boolean com.hyphenate.chat.EMChatManager.deleteConversation ( String  username,
boolean  deleteMessages 
)

删除指定会话及其本地历史消息。

参数
username会话 ID。
deleteMessages删除会话时是否同时删除本地的历史消息。
  • true:删除;
  • false:不删除。
返回
会话是否删除成功。
  • true:是;
  • false: 否。

◆ deleteConversationFromServer()

void com.hyphenate.chat.EMChatManager.deleteConversationFromServer ( String  username,
EMConversationType  type,
boolean  isDeleteServerMessages,
EMCallBack  deleteCallBack 
)

删除服务端的指定会话及其历史消息。

异步方法。

参数
username会话 ID。
type会话类型,详见 EMConversationType
isDeleteServerMessages删除会话时是否同时删除历史消息。
  • true:是;
  • false: 否。
deleteCallBack删除服务端会话及其历史消息成功与否的回调。
  • true:删除成功;
  • false:删除失败。

◆ deleteMessagesBeforeTimestamp()

void com.hyphenate.chat.EMChatManager.deleteMessagesBeforeTimestamp ( long  timeStamp,
EMCallBack  callback 
)

删除指定时间戳之前的本地历史消息。

参数
timeStamp查询的消息的起始 Unix 时间戳,单位为毫秒。
callback删除结果回调,详见 EMCallBack

◆ downloadAndParseCombineMessage()

void com.hyphenate.chat.EMChatManager.downloadAndParseCombineMessage ( EMMessage  message,
EMValueCallBack< List< EMMessage > >  callback 
)

下载并解析合并消息的附件。

对于一条合并消息,首次调用该方法会下载和解析合并消息附件,然后返回消息列表,而后续调用会存在以下情况:

  1. 若附件已存在,该方法会直接解析附件并返回消息列表。
  2. 若附件不存在,该方法首先会下载附件,然后解析合并消息附件并返回消息列表。
参数
message要下载和解析的合并消息。
callback结果回调,成功时回调 EMValueCallBack#onSuccess(Object),返回解析成功的消息列表; 失败时回调 EMValueCallBack#onError(int, String)

◆ downloadAttachment()

void com.hyphenate.chat.EMChatManager.downloadAttachment ( final EMMessage  msg)

下载消息的附件。

若附件自动下载失败,也可以调用此方法下载。

参数
msg要下载附件的消息。

◆ downloadThumbnail()

void com.hyphenate.chat.EMChatManager.downloadThumbnail ( final EMMessage  msg)

下载消息的缩略图。

参数
msg要下载缩略图的消息。只有图片消息和视频消息有缩略图。

◆ fetchConversationsFromServer()

Map< String, EMConversation > com.hyphenate.chat.EMChatManager.fetchConversationsFromServer ( ) throws HyphenateException

从服务器获取会话列表。

用户默认可拉取 7 天内的 10 个会话(每个会话包含最新一条历史消息)。

同步方法,会阻塞当前线程。

返回
当前用户的会话列表。
弃用:
已废弃。请用 asyncFetchConversationsFromServer(int, String, EMValueCallBack) 代替。

◆ fetchGroupReadAcks()

EMCursorResult< EMGroupReadAck > com.hyphenate.chat.EMChatManager.fetchGroupReadAcks ( String  msgId,
int  pageSize,
String  startAckId 
) throws HyphenateException

从服务器分页获取群组消息已读回执详情。

发送群组消息回执,可调用 ackGroupMessageRead(String, String, String)

同步方法,会阻塞当前线程。

参数
msgId消息 ID。
pageSize每页期望返回的群消息已读数。取值范围[1,50]。
startAckId查询起始的已读回执 ID。该参数设置后,SDK 从指定的已读回执 ID 开始,按服务器接收已读回执的时间的逆序获取。 若该参数为空,SDK 从最新的已读回执开始按服务器接收回执时间的逆序获取。
返回
返回消息列表(不包含查询起始 ID 的已读回执)和用于继续获取群消息回执的 cursor。
异常
HyphenateException如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError

◆ fetchHistoryMessages() [1/2]

EMCursorResult< EMMessage > com.hyphenate.chat.EMChatManager.fetchHistoryMessages ( String  conversationId,
EMConversationType  type,
int  pageSize,
String  startMsgId 
) throws HyphenateException

从服务器分页获取指定会话的所有类型的历史消息。

同步方法,会阻塞当前线程。

参数
conversationId会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID。
type会话类型, 详见 EMConversationType
pageSize每页期望获取的消息条数。取值范围为 [1,50]。
startMsgId开始获取的消息 ID。该参数设置后,SDK 从指定的消息 ID 开始,按服务器接收消息的时间的逆序获取。 若该参数为空,SDK 从最新的消息开始,按服务器接收消息的时间的逆序获取。
返回
消息列表(不包含查询起始 ID 的消息)和下次查询的 cursor。
异常
HyphenateException如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError
弃用:
已废弃。请用 asyncFetchHistoryMessages(String, EMConversationType, int, String, EMFetchMessageOption, EMValueCallBack) 代替。

◆ fetchHistoryMessages() [2/2]

EMCursorResult< EMMessage > com.hyphenate.chat.EMChatManager.fetchHistoryMessages ( String  conversationId,
EMConversationType  type,
int  pageSize,
String  startMsgId,
EMConversation.EMSearchDirection  direction 
) throws HyphenateException

从服务器分页按消息搜索方向获取指定会话的所有类型的历史消息。

同步方法,会阻塞当前线程。

参数
conversationId会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID。
type会话类型。详见 EMConversationType
pageSize每页期望获取的消息条数。取值范围为 [1,50]。
startMsgId查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始,按消息检索方向获取。如果传入消息的 ID 为空,SDK 忽略该参数,按搜索方向查询消息。
  • directionUP,SDK 从最新消息开始,按照服务器接收消息时间的逆序获取;
  • directionDOWN,SDK 从最早消息开始,按照服务器接收消息时间的正序获取。
direction消息搜索方向。详见 EMConversation.EMSearchDirection
  • (默认)UP:按照服务器接收消息时间的逆序获取;
  • DOWN:按照服务器接收消息时间的正序获取。
返回
消息列表(不包含查询起始 ID 的消息)和下次查询的 cursor。
异常
HyphenateException如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError
弃用:
已废弃。请用 asyncFetchHistoryMessages(String, EMConversationType, int, String, EMFetchMessageOption, EMValueCallBack) 代替。

◆ fetchSupportLanguages()

void com.hyphenate.chat.EMChatManager.fetchSupportLanguages ( EMValueCallBack< List< EMLanguage > >  callback)

获取翻译服务支持的语言。

参数
callback结果回调,详见 EMCallBack

◆ getAllConversations()

Map< String, EMConversation > com.hyphenate.chat.EMChatManager.getAllConversations ( )

获取本地当前所有会话。

该方法会先从内存中获取,如果未找到任何会话,从本地数据库获取。

返回
本地内存或者数据库中所有的会话。

◆ getAllConversationsBySort()

List< EMConversation > com.hyphenate.chat.EMChatManager.getAllConversationsBySort ( )

获取本地当前所有会话。

SDK 按照最近一条消息的时间戳的倒序返回会话,置顶会话在前,非置顶会话在后。

该方法会先从内存中获取,如果未找到任何会话,SDK 从本地数据库获取。

返回
排序后的会话列表。

◆ getConversation() [1/4]

EMConversation com.hyphenate.chat.EMChatManager.getConversation ( String  id)

获取指定 ID 的会话对象。

参数
id会话 ID。
返回
根据指定会话 ID 找到的会话对象,如果没有找到会返回空值。

◆ getConversation() [2/4]

EMConversation com.hyphenate.chat.EMChatManager.getConversation ( String  id,
EMConversationType  type 
)

根据会话 ID 以及会话类型获取会话。

没有找到返回空值。

参数
id会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID;
  • 聊天室:聊天室 ID;
  • 子区:子区 ID。
type会话类型,详见 EMConversationType
返回
根据指定 ID 以及会话类型找到的会话对象,未找到会返回空值。

◆ getConversation() [3/4]

EMConversation com.hyphenate.chat.EMChatManager.getConversation ( String  username,
EMConversationType  type,
boolean  createIfNotExists 
)

根据会话 ID 和会话类型获取会话。

参数
username会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID;
  • 聊天室:聊天室 ID;
  • 子区:子区 ID。
type会话类型,详见 EMConversationType
createIfNotExists未找到指定会话时是否创建一个新会话。
  • true:是;
  • false:否。
返回
找到的会话对象,如果未找到,返回空值。

◆ getConversation() [4/4]

EMConversation com.hyphenate.chat.EMChatManager.getConversation ( String  username,
EMConversationType  type,
boolean  createIfNotExists,
boolean  isChatThread 
)

根据会话 ID 以及会话类型获取会话。

参数
username会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID;
  • 聊天室:聊天室 ID;
  • 子区:子区 ID。
type会话类型,详见 EMConversationType
createIfNotExists未找到指定会话时是否创建一个新会话。
  • true:是;
    • false:否。
isChatThread是否查找子区会话。
  • true:是;
    • false:否。
返回
找到的会话对象。如果未找到,返回空值。

◆ getConversationsByType()

List< EMConversation > com.hyphenate.chat.EMChatManager.getConversationsByType ( EMConversationType  type)

获取指定类型的所有会话。

参数
type会话类型,详见 EMConversationType
返回
指定类型的会话列表。

◆ getMessage()

EMMessage com.hyphenate.chat.EMChatManager.getMessage ( String  messageId)

获取指定 ID 的消息对象。

参数
messageId消息 ID。
返回
根据指定 ID 获取的消息对象,如果消息不存在会返回空值。

◆ getReactionDetail()

EMCursorResult< EMMessageReaction > com.hyphenate.chat.EMChatManager.getReactionDetail ( final String  messageId,
final String  reaction,
final String  cursor,
final int  pageSize 
) throws HyphenateException

获取 Reaction 详细信息。

同步方法。

参数
messageId消息 ID。
reaction消息 Reaction 内容。
cursor查询的起始游标位置。
pageSize每页期望获取的 Reaction 数。
返回
获取结果 EMCursorResult,包含 cursor 和 Reaction 列表。若 cursor 为空表示数据已全部获取。

◆ getReactionList()

Map< String, List< EMMessageReaction > > com.hyphenate.chat.EMChatManager.getReactionList ( final List< String >  messageIdList,
final EMMessage.ChatType  chatType,
final String  groupId 
) throws HyphenateException

获取 Reaction 列表。

同步方法。

参数
messageIdList消息 ID。
chatType会话类型,仅支持单聊(EMMessage.ChatType#Chat)和群聊(EMMessage.ChatType#GroupChat)。
groupId群组 ID,该参数仅对群聊生效。
返回
map 指定消息 ID 对应的 Reaction 列表(EMMessageReaction 的用户列表 UserList 为概要数据,只包含前三个用户信息)。

◆ getUnreadMessageCount()

int com.hyphenate.chat.EMChatManager.getUnreadMessageCount ( )

获取未读消息数。

返回
未读消息数。

◆ importMessages()

synchronized void com.hyphenate.chat.EMChatManager.importMessages ( List< EMMessage msgs)

将消息导入本地数据库。

你只能将你发送或接收的消息导入本地数据库。

推荐一次导入 1,000 条以内的数据。

参数
msgs需要导入数据库的消息。

◆ loadAllConversations()

void com.hyphenate.chat.EMChatManager.loadAllConversations ( )

从数据库加载本地所有的会话到内存中。

一般在登录成功后使用此方法,可以加快会话列表的加载速度。

◆ markAllConversationsAsRead()

boolean com.hyphenate.chat.EMChatManager.markAllConversationsAsRead ( )

将所有会话都设成已读。

该方法仅适用于本地会话。

返回
是否成功标记所有会话为已读。

◆ recallMessage() [1/2]

void com.hyphenate.chat.EMChatManager.recallMessage ( EMMessage  message) throws HyphenateException

撤回发送成功的消息。

若消息发送和撤回时接收方为离线状态,接收方会收到消息撤回回调 EMMessageListener#onMessageRecalled,不会收到该消息。

同步方法,会阻塞当前线程。

参数
message消息对象。
异常
HyphenateException如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError

◆ recallMessage() [2/2]

void com.hyphenate.chat.EMChatManager.recallMessage ( EMMessage  message,
String  ext 
) throws HyphenateException

撤回发送成功的消息。

若消息发送和撤回时接收方为离线状态,接收方会收到消息撤回回调 EMMessageListener#onMessageRecalled,不会收到该消息。

同步方法,会阻塞当前线程。

参数
message消息对象。
ext扩展信息
异常
HyphenateException如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError

◆ removeConversationListener()

void com.hyphenate.chat.EMChatManager.removeConversationListener ( EMConversationListener  listener)

移除会话监听器。

调用 addConversationListener(EMConversationListener) 添加会话监听器后再调用本方法移除。

参数
listener要移除的会话监听器,详见 EMConversationListener

◆ removeMessageListener()

void com.hyphenate.chat.EMChatManager.removeMessageListener ( EMMessageListener  listener)

移除消息监听器。

调用 addMessageListener(EMMessageListener) 添加消息监听后再调用本方法移除。

参数
listener要移除的监听器,详见 EMMessageListener

◆ removeMessagesFromServer() [1/2]

void com.hyphenate.chat.EMChatManager.removeMessagesFromServer ( String  conversationId,
EMConversationType  type,
List< String >  msgIdList,
EMCallBack  callBack 
)
protected

根据消息 ID 单向删除漫游消息。

参数
conversationId会话 ID。
type会话类型。
msgIdList要删除的消息 ID 列表。
callBack处理结果回调,详见 EMCallBack

◆ removeMessagesFromServer() [2/2]

void com.hyphenate.chat.EMChatManager.removeMessagesFromServer ( String  conversationId,
EMConversationType  type,
long  beforeTimeStamp,
EMCallBack  callBack 
)
protected

根据时间戳单向删除漫游消息。

参数
conversationId会话 ID。
type会话类型。
beforeTimeStampUNIX 时间戳,单位为毫秒。若消息的 UNIX 时间戳小于设置的值,则会被删除。
callBack处理结果回调,详见 EMCallBack

◆ removeReaction()

void com.hyphenate.chat.EMChatManager.removeReaction ( final String  messageId,
final String  reaction 
) throws HyphenateException

删除 Reaction。

同步方法。

参数
messageId消息 ID。
reaction要删除的 Reaction。
异常
HyphenateException如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError

◆ reportMessage()

void com.hyphenate.chat.EMChatManager.reportMessage ( String  msgId,
String  tag,
String  reportReason 
) throws HyphenateException

举报非法消息。

同步方法,会阻塞当前线程。

参数
msgId要举报的消息 ID。
tag非法消息的标签。你需要填写自定义标签,例如涉政广告
reportReason举报原因。你需要自行填写举报原因。
异常
HyphenateException如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError

◆ saveMessage()

void com.hyphenate.chat.EMChatManager.saveMessage ( EMMessage  message)

保存消息到内存和本地数据库。

命令消息(类型见:Type#CMD,消息体见:EMCmdMessageBody)不会在本地保存。

参数
message待存储的消息。

◆ searchMsgFromDB() [1/3]

List< EMMessage > com.hyphenate.chat.EMChatManager.searchMsgFromDB ( String  keywords,
long  timeStamp,
int  maxCount,
String  from,
EMConversation.EMSearchDirection  direction 
)

从本地数据库获取指定会话中包含特定关键字的消息。

参数
keywords查询关键字。
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
maxCount每次获取的最大消息数。取值范围为 [1,400]。
from单聊或群聊中的消息发送方的用户 ID。若设置为 null 或空字符串,SDK 将在整个会话中搜索消息。
direction消息搜索方向。详见 EMConversation.EMSearchDirection
  • (默认)UP:按照消息中的时间戳的逆序查询;
    • DOWN:按照消息中的时间戳的正序查询。
返回
消息列表(不包含查询起始时间戳对应的消息)。若未查找到任何消息,返回空列表。

◆ searchMsgFromDB() [2/3]

List< EMMessage > com.hyphenate.chat.EMChatManager.searchMsgFromDB ( String  keywords,
long  timeStamp,
int  maxCount,
String  from,
EMConversation.EMSearchDirection  direction,
EMConversation.EMMessageSearchScope  searchScope 
)

从本地数据库获取包含特定关键字的消息。

参数
keywords查询关键字。
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
maxCount每次获取的最大消息数。取值范围为 [1,400]。如果设为小于等于 0,SDK 会获取一条消息。
from单聊或群聊中的消息发送方的用户 ID。若设置为 null 或空字符串,SDK 将在整个会话中搜索消息。
direction消息搜索方向。详见 EMConversation.EMSearchDirection
  • (默认)UP:按照消息中的时间戳的逆序查询;
    • DOWN:按照消息中的时间戳的正序查询。
searchScope消息搜索范围。详见 EMConversation.EMMessageSearchScope
返回
消息列表(不包含查询起始时间戳对应的消息)。若未查找到任何消息,返回空列表。

◆ searchMsgFromDB() [3/3]

List< EMMessage > com.hyphenate.chat.EMChatManager.searchMsgFromDB ( Type  type,
long  timeStamp,
int  maxCount,
String  from,
EMConversation.EMSearchDirection  direction 
)

从本地数据库获取指定会话的一定数量的特定类型的消息。

参数
type消息类型。详见 Type
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
maxCount每次获取的最大消息数。取值范围为 [1,400]。
from单聊或群聊中的消息发送方的用户 ID。若设置为 null 或空字符串,SDK 将在整个会话中搜索消息。
direction消息搜索方向。详见 EMConversation.EMSearchDirection
  • (默认)UP:按照消息中的时间戳的逆序查询;
    • DOWN:按照消息中的时间戳的正序查询。
返回
消息列表(不包含查询起始时间戳对应的消息)。若未查找到任何消息,返回空列表。

◆ sendMessage()

void com.hyphenate.chat.EMChatManager.sendMessage ( final EMMessage  msg)

发送消息。

如果是语音,图片类等有附件的消息,SDK 会自动上传附件。

可以通过 EMOptions#setAutoTransferMessageAttachments(boolean) 设置是否上传到聊天服务器。

发送消息的状态,可以通过设置 EMMessage#setMessageStatusCallback(EMCallBack) 进行监听。

参数
msg要发送的消息,必填。

◆ setVoiceMessageListened()

void com.hyphenate.chat.EMChatManager.setVoiceMessageListened ( EMMessage  message)

将语音消息设置为已听。

参数
message要设置的消息对象。

◆ translateMessage()

void com.hyphenate.chat.EMChatManager.translateMessage ( EMMessage  message,
List< String >  languages,
EMValueCallBack< EMMessage callback 
)

翻译一条文本消息。

参数
message要翻译的消息对象。
languages目标语言代码列表。
callback结果回调,详见 EMCallBack

◆ updateMessage()

boolean com.hyphenate.chat.EMChatManager.updateMessage ( EMMessage  message)

更新本地消息。

该方法会同时更新本地内存和数据库中的消息。

参数
message要更新的消息对象。

◆ updateParticipant()

boolean com.hyphenate.chat.EMChatManager.updateParticipant ( String  from,
String  changeTo 
)

将数据库中指定联系人的相关信息变更成另外一个联系人。

注意

  • 消息列表,会话列表,联系人列表和黑名单列表等相关信息会发生变化。
  • 该方法不会更新内存中数据。
参数
from原联系人的用户 ID。
changeTo新联系人的用户 ID。
返回
返回更新结果,任何列表更新失败,均会返回 false

该类的文档由以下文件生成: