hyphenate_SDK3.0
3.8.6.1
hyphenate java IM SDK
|
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 | aysncRecallMessage (final EMMessage message, 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) |
void | markAllConversationsAsRead () |
int | getUnreadMsgsCount () |
int | getUnreadMessageCount () |
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< EMConversation > | getConversationsByType (EMConversationType type) |
void | downloadFile (final String remoteUrl, final String localFilePath, final Map< String, String > headers, final EMCallBack callback) |
Map< String, EMConversation > | getAllConversations () |
Map< String, EMConversation > | fetchConversationsFromServer () throws HyphenateException |
void | asyncFetchConversationsFromServer (final EMValueCallBack< Map< String, EMConversation >> callBack) |
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) |
void | setVoiceMessageListened (EMMessage message) |
boolean | updateParticipant (String from, String changeTo) |
EMCursorResult< EMGroupReadAck > | fetchGroupReadAcks (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< EMMessage > | fetchHistoryMessages (String conversationId, EMConversationType type, int pageSize, String startMsgId) throws HyphenateException |
void | asyncFetchHistoryMessage (final String conversationId, final EMConversationType type, final int pageSize, final String startMsgId, final EMValueCallBack< EMCursorResult< EMMessage >> callBack) |
List< EMMessage > | searchMsgFromDB (EMMessage.Type type, long timeStamp, int maxCount, String from, EMConversation.EMSearchDirection direction) |
List< EMMessage > | searchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMConversation.EMSearchDirection direction) |
Protected 成员函数 | |
EMChatManager (EMClient client, EMAChatManager manager) | |
聊天管理类,负责管理会话(加载,删除等),发送消息,下载消息附件等 比如,发送一条文本消息:
EMMessage message = EMMessage.createTxtSendMessage(content, toChatUsername); EMClient.getInstance().chatManager().sendMessage(message);
void com.hyphenate.chat.EMChatManager.ackConversationRead | ( | String | conversationId | ) | throws HyphenateException |
发送会话已读回执,只针对单聊会话 将通知服务器将此会话未读数置为0,对话方(包含多端多设备)将会在回调方法 EMConversationListener#onConversationRead(String, String) 中接收到回调
群消息已读回执,详见ackGroupMessageRead(String, String, String)
建议:此方法可以在进入聊天页面时调用,在聊天过程中调用 ackMessageRead(String, String), 可以在有大量未读消息时,减少调用 ackMessageRead(String, String) 的次数
conversationId | 会话ID |
HyphenateException | 可能会抛出的异常 EMError#USER_NOT_LOGIN、EMError#SERVER_NOT_REACHABLE、 EMError#MESSAGE_INVALID等,详见EMError |
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 |
void com.hyphenate.chat.EMChatManager.ackMessageRead | ( | String | to, |
String | messageId | ||
) | throws HyphenateException |
发送消息已读回执,只针对单聊消息 前提条件:设置了EMOptions#setRequireAck(boolean)
发送群消息已读回执,详见ackGroupMessageRead(String, String, String)
建议:在进入聊天页面的时调用 ackConversationRead(String) ,其他场景再调用此方法,可以大量减少调用此方法的次数
to | 接收方的用户名 |
messageId | 消息的ID |
HyphenateException | 抛出的异常,详见EMError |
void com.hyphenate.chat.EMChatManager.addConversationListener | ( | EMConversationListener | listener | ) |
注册会话监听 用于监听会话变化及监听会话已读回执,详见EMConversationListener 需要配合removeConversationListener(EMConversationListener) 使用
listener | 要添加的会话监听,详见EMConversationListener |
void com.hyphenate.chat.EMChatManager.addMessageListener | ( | EMMessageListener | listener | ) |
注册消息监听 接受到新消息等回调可以通过设置此方法进行监听,详见EMMessageListener 需要和removeMessageListener(EMMessageListener) 配合使用
listener | 要注册的消息监听,详见EMMessageListener |
void com.hyphenate.chat.EMChatManager.asyncFetchConversationsFromServer | ( | final EMValueCallBack< Map< String, EMConversation >> | callBack | ) |
从服务器获取会话列表 默认最多返回100条数据
异步方法
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 | 每次获取群消息已读回执的条数 |
startAckId | 已读回执的id,如果为空,从最新的回执向前开始获取 |
callBack | 结果回调,成功执行EMValueCallBack#onSuccess(Object),失败执行EMValueCallBack#onError(int, String) |
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 |
type | 会话类型,详见EMConversationType |
pageSize | 每次获取的条数 |
startMsgId | 漫游消息的开始消息id,如果为空,从最新的消息向前开始获取 |
callBack | 结果回调,成功执行EMValueCallBack#onSuccess(Object), 返回消息列表和用于继续获取历史消息的Cursor; 失败执行EMValueCallBack#onError(int, String) |
void com.hyphenate.chat.EMChatManager.aysncRecallMessage | ( | final EMMessage | message, |
final EMCallBack | callback | ||
) |
boolean com.hyphenate.chat.EMChatManager.deleteConversation | ( | String | username, |
boolean | deleteMessages | ||
) |
删除指定ID的对话和本地的聊天记录 如果将deleteMessages设为true,删除会话的同时也会删除本地的聊天记录
username | 会话ID |
deleteMessages | 是否同时删除本地的聊天记录 |
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 | 本地要生成的文件路径 |
headers | 请求头 |
callback | 下载结果回调,详见EMCallBack |
void com.hyphenate.chat.EMChatManager.downloadThumbnail | ( | final EMMessage | msg | ) |
下载消息的缩略图
msg | 要下载缩略图的消息,一般是图片消息和视频消息 |
Map<String, EMConversation> com.hyphenate.chat.EMChatManager.fetchConversationsFromServer | ( | ) | throws HyphenateException |
从服务器获取会话列表 默认最多返回100条数据
同步方法,会阻塞当前线程
EMCursorResult<EMGroupReadAck> com.hyphenate.chat.EMChatManager.fetchGroupReadAcks | ( | String | msgId, |
int | pageSize, | ||
String | startAckId | ||
) | throws HyphenateException |
从服务器获取群组消息回执详情 分页获取 发送群组消息回执,详见ackGroupMessageRead(String, String, String)
同步方法,会阻塞当前线程
msgId | 需要获取回执的消息id |
pageSize | 每次获取群消息已读回执的条数 |
startAckId | 已读回执的id,可以为空。如果为空,从最新的回执向前开始获取 |
HyphenateException | 错误码详见EMError |
EMCursorResult<EMMessage> com.hyphenate.chat.EMChatManager.fetchHistoryMessages | ( | String | conversationId, |
EMConversationType | type, | ||
int | pageSize, | ||
String | startMsgId | ||
) | throws HyphenateException |
从服务器获取历史消息 分页获取
同步方法,会阻塞当前线程
conversationId | 会话ID |
type | 会话类型, 详见EMConversationType |
pageSize | 每次获取的条数 |
startMsgId | 漫游消息的开始消息id,如果为空,从最新的消息向前开始获取 |
HyphenateException | 错误码详见EMError |
Map<String, EMConversation> com.hyphenate.chat.EMChatManager.getAllConversations | ( | ) |
从本地获取当前所有的会话 先从内存中加载,如果内存中没有再从数据库中加载
EMConversation com.hyphenate.chat.EMChatManager.getConversation | ( | String | id | ) |
获取定义ID的会话对象 没有找到返回空
id | 会话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以及会话类型获取会话 没有找到的话,根据createIfNotExists的值返回一个新建对象或者空对象
username | 会话ID |
type | 会话类型 |
createIfNotExists | 没找到相应会话时是否自动创建 |
List<EMConversation> com.hyphenate.chat.EMChatManager.getConversationsByType | ( | EMConversationType | type | ) |
EMMessage com.hyphenate.chat.EMChatManager.getMessage | ( | String | messageId | ) |
获取指定ID 的消息对象
messageId | 消息ID |
int com.hyphenate.chat.EMChatManager.getUnreadMessageCount | ( | ) |
获取未读消息数
int com.hyphenate.chat.EMChatManager.getUnreadMsgsCount | ( | ) |
synchronized void com.hyphenate.chat.EMChatManager.importMessages | ( | List< EMMessage > | msgs | ) |
向消息数据库导入多条聊天记录 在调用次函数时要保证,消息的发送方或者接收方是当前用户 已经对函数做过速度优化, 推荐一次导入1000条数据
msgs | 需要导入数据库的消息 |
void com.hyphenate.chat.EMChatManager.loadAllConversations | ( | ) |
从数据库加载本地所有的会话到内存中 一般在登录成功后使用此方法,可以加快会话列表的加载速度
void com.hyphenate.chat.EMChatManager.markAllConversationsAsRead | ( | ) |
把所有的会话都设成已读 针对的是本地会话
void com.hyphenate.chat.EMChatManager.recallMessage | ( | EMMessage | message | ) | throws HyphenateException |
void com.hyphenate.chat.EMChatManager.removeConversationListener | ( | EMConversationListener | listener | ) |
移除会话监听 需要添加addConversationListener(EMConversationListener) 后调用此方法进行移除
listener | 需要移除的会话监听,详见EMConversationListener |
void com.hyphenate.chat.EMChatManager.removeMessageListener | ( | EMMessageListener | listener | ) |
移除消息监听 添加addMessageListener(EMMessageListener) 后需要调用本方法
listener | 要移除的监听,详见EMMessageListener |
void com.hyphenate.chat.EMChatManager.saveMessage | ( | EMMessage | message | ) |
保存消息到本地 比如系统提示消息会存到内存中的会话和数据库 CMD类型数据不保存在本地
message | 待存储的消息 |
List<EMMessage> com.hyphenate.chat.EMChatManager.searchMsgFromDB | ( | EMMessage.Type | type, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
EMConversation.EMSearchDirection | direction | ||
) |
根据传入的参数从本地存储中搜索指定数量的消息 注意:当maxCount非常大时,需要考虑内存消耗,目前限制一次最多搜索400条数据
type | 消息类型,文本、图片、语音等,详见EMMessage.Type |
timeStamp | 搜索消息的时间点 |
maxCount | 搜索结果的最大条数 |
from | 搜索来自某人或者某群的消息,一般是指会话ID |
List<EMMessage> com.hyphenate.chat.EMChatManager.searchMsgFromDB | ( | String | keywords, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
EMConversation.EMSearchDirection | direction | ||
) |
根据传入的参数从本地存储中搜索指定数量的消息 注意:当maxCount非常大时,需要考虑内存消耗,目前限制一次最多搜索400条数据
keywords | 搜索消息中的关键词 |
timeStamp | 搜索消息的时间点 |
maxCount | 搜索结果的最大条数 |
from | 搜索来自某人或者某群的消息,一般是指会话ID |
void com.hyphenate.chat.EMChatManager.sendMessage | ( | final EMMessage | msg | ) |
发送消息 如果是语音,图片类等有附件的消息,SDK会自动上传附件 可以通过 EMOptions#setAutoTransferMessageAttachments(boolean) 设置是否上传到聊天服务器,默认为true 发送消息的状态,可以通过设置 EMMessage#setMessageStatusCallback(EMCallBack) 进行监听,这里需要注意的是 需要将抓过状态监听设置在sendMessage()方法调用之前,否则设置的监听有可能会被系统回收
msg | 待发送消息对象,不能为空 |
void com.hyphenate.chat.EMChatManager.setMessageListened | ( | EMMessage | message | ) |
void com.hyphenate.chat.EMChatManager.setVoiceMessageListened | ( | EMMessage | message | ) |
将消息设置为已听,一般用于语音消息
message | 要设置的消息对象 |
boolean com.hyphenate.chat.EMChatManager.updateMessage | ( | EMMessage | message | ) |
更新本地消息 会更新本地内存和数据库
message | 要更新的消息对象 |
boolean com.hyphenate.chat.EMChatManager.updateParticipant | ( | String | from, |
String | changeTo | ||
) |
将数据库中的某个联系人相关信息变更成另外一个联系人 与变更相关的表单包含消息表单,会话表单,联系人表单,黑名单表单 注意:该操作不会更新内存中数据
from | 更换前的用户ID |
changeTo | 更换后的用户ID |