hyphenate_SDK3.0  3.0.1
hyphenatejavaIMSDK
Public 成员函数 | Protected 成员函数 | 所有成员列表
com.hyphenate.chat.EMChatManager类 参考

Public 成员函数

void sendMessage (final EMMessage msg)
 
void ackMessageRead (String to, String messageId) throws HyphenateException
 
EMMessage getMessage (String messageId)
 
EMConversation getConversation (String id)
 
EMConversation getConversation (String id, EMConversationType type)
 
EMConversation getConversation (String username, EMConversationType type, boolean createIfNotExists)
 
void markAllConversationsAsRead ()
 
int getUnreadMsgsCount ()
 
void saveMessage (EMMessage message)
 
boolean updateMessage (EMMessage message)
 
void downloadAttachment (final EMMessage msg)
 
void downloadThumbnail (final EMMessage msg)
 
synchronized void importMessages (List< EMMessage > msgs)
 
List< EMConversationgetConversationsByType (EMConversation.EMConversationType type)
 
boolean isSlientMessage (EMMessage message)
 
void downloadFile (final String remoteUrl, final String localFilePath, final Map< String, String > headers, final EMCallBack callback)
 
Map< String, EMConversationgetAllConversations ()
 
void loadAllConversations ()
 
boolean deleteConversation (String username, boolean deleteMessages)
 
void addMessageListener (EMMessageListener listener)
 
void removeMessageListener (EMMessageListener listener)
 
void addConversationListener (EMConversationListener listener)
 
void removeConversationListener (EMConversationListener listener)
 
void setMessageListened (EMMessage message)
 

Protected 成员函数

 EMChatManager (EMClient client, EMAChatManager manager)
 

详细描述

send a message
EMMessage msg = EMMessage;
EMClient.getInstance().chatManager().sendMessage(msg);

成员函数说明

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

发送消息已读回执

参数
to接收方的用户名
messageId消息的ID
异常
HyphenateException
void com.hyphenate.chat.EMChatManager.addConversationListener ( EMConversationListener  listener)

注册会话监听

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

注册消息监听

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

删除和指定用户或者群聊的对话(包括删除本地的聊天记录)

参数
username用户名或者群聊id
deleteMessages是否删除消息
返回
删除失败或者不存在此user的conversation返回false
void com.hyphenate.chat.EMChatManager.downloadAttachment ( final EMMessage  msg)

下载消息的附件,未成功下载的附件,可调用此方法再次下载

参数
msg
void com.hyphenate.chat.EMChatManager.downloadFile ( final String  remoteUrl,
final String  localFilePath,
final Map< String, String >  headers,
final EMCallBack  callback 
)

从环信服务器下载文件

参数
remoteUrl服务器上的远程文件
localFilePath本地要生成的文件
headersHttp Request Header
callbackEMCallBack
void com.hyphenate.chat.EMChatManager.downloadThumbnail ( final EMMessage  msg)

下载消息的缩略图

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

获取当前所有的会话

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

获取会话,没有则返回null, 没找到则返回空

参数
iduser id or group id
EMConversation com.hyphenate.chat.EMChatManager.getConversation ( String  id,
EMConversationType  type 
)

根据用户或群组id以及会话类型获取会话,没有找到则返回空

参数
id用户或群组id
type会话类型
返回
EMConversation com.hyphenate.chat.EMChatManager.getConversation ( String  username,
EMConversationType  type,
boolean  createIfNotExists 
)

根据用户或群组id以及会话类型获取会话

参数
username用户或群组id
type会话类型
createIfNotExists没找到相应会话时是否自动创建
返回
List<EMConversation> com.hyphenate.chat.EMChatManager.getConversationsByType ( EMConversation.EMConversationType  type)

获取某个类型所有的会话

返回
会话list
EMMessage com.hyphenate.chat.EMChatManager.getMessage ( String  messageId)

获取指定ID 的消息对象

参数
messageId消息ID
返回
int com.hyphenate.chat.EMChatManager.getUnreadMsgsCount ( )

获取未读消息计数

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

向消息数据库导入多条聊天记录 在调用次函数时要保证,消息的发送方或者接收方是当前用户 已经对函数做过速度优化, 推荐一次导入1000条数据

参数
msgs需要导入数据库的消息
boolean com.hyphenate.chat.EMChatManager.isSlientMessage ( EMMessage  message)

判断是否是免打扰的消息,如果是app中应该不要给用户提示新消息

参数
messagereturn
void com.hyphenate.chat.EMChatManager.loadAllConversations ( )

同步加载所有的会话,并且每条会话读入EMChatOptions.getNumberOfMessagesLoaded()条消息, 默认是20条以保持兼容 APP可以在用EMChatOptions.setNumberOfMessagesLoaded去设置初始条数(建议是1)

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

把所有的会话都设成已读

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

移除会话监听

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

移除消息监听

参数
listener要移除的监听
void com.hyphenate.chat.EMChatManager.saveMessage ( EMMessage  message)

保存用户app 生成的消息,比如系统提示 消息会存到内存中的conversation 和数据库

参数
message待存储的消息
void com.hyphenate.chat.EMChatManager.sendMessage ( final EMMessage  msg)

异步发送消息 如果是语音,图片类有附件的消息,sdk 会自动上传附件

参数
msg待发送消息对象
异常
HyphenateException网络错误或其它异常
void com.hyphenate.chat.EMChatManager.setMessageListened ( EMMessage  message)

设置消息为已听,一般用于语音消息

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

更新消息,消息的内容会被保存到本地

参数
message

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