hyphenate_SDK4.0 4.2.3-lite
hyphenate java IM SDK
|
Public Member Functions | |
void | sendMessage (final EMMessage msg) |
void | ackConversationRead (String conversationId) throws HyphenateException |
void | ackMessageRead (String to, String messageId) throws HyphenateException |
void | recallMessage (EMMessage message) throws HyphenateException |
void | asyncRecallMessage (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) |
EMConversation | getConversation (String username, EMConversationType type, boolean createIfNotExists, boolean isChatThread) |
int | getUnreadMessageCount () |
void | saveMessage (EMMessage message) |
void | downloadAttachment (final EMMessage msg) |
void | downloadThumbnail (final EMMessage msg) |
List< EMConversation > | getConversationsByType (EMConversationType type) |
Map< String, EMConversation > | getAllConversations () |
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) |
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) |
void | asyncFetchHistoryMessages (String conversationId, EMConversationType type, int pageSize, String cursor, EMFetchMessageOption option, final EMValueCallBack< EMCursorResult< EMMessage > > callBack) |
Protected Member Functions | |
void | removeMessagesFromServer (String conversationId, EMConversationType type, long beforeTimeStamp, EMCallBack callBack) |
The chat manager class, responsible for sending and receiving messages, managing conversations (including loading and deleting conversations), and downloading attachments.
The sample code for sending a text message is as follows:
void com.hyphenate.chat.EMChatManager.ackConversationRead | ( | String | conversationId | ) | throws HyphenateException |
Sends the conversation read receipt to the server.
This method is only for one-to-one chat conversations.
This method will inform the sever to set the unread message count of the conversation to 0
. The message sender will receive the EMConversationListener#onConversationRead(String, String) callback. The message recipient that has logged in to multiple devices, will also receive the callback.
conversationId | The conversation ID. |
HyphenateException | The possible exceptions are as follows: EMError#USER_NOT_LOGIN, EMError#SERVER_NOT_REACHABLE, and EMError#MESSAGE_INVALID. See EMError. |
void com.hyphenate.chat.EMChatManager.ackMessageRead | ( | String | to, |
String | messageId | ||
) | throws HyphenateException |
Sends the read receipt for a message to the server.
Note
This method applies to one-to-one chats only.
This method only takes effect if you set EMOptions#setRequireAck(boolean) as true
.
We recommend that you call ackConversationRead(String) when opening the chat page, and call this method in other cases to reduce the number of method calls.
to | The message for which the read receipt is to be sent. |
messageId | The message ID. |
HyphenateException | A description of the exception, see EMError. |
void com.hyphenate.chat.EMChatManager.addConversationListener | ( | EMConversationListener | listener | ) |
Adds the conversation listener.
After a conversation listener is added, you can listen for conversation changes and conversation read receipts.
You can call the removeConversationListener(EMConversationListener) method to remove the conversation listener when it is not required.
listener | The conversation listener to add. See EMConversationListener. |
void com.hyphenate.chat.EMChatManager.addMessageListener | ( | EMMessageListener | listener | ) |
Adds the message listener.
After a message listener is added, you can listen for new messages when they arrive.
You can call removeMessageListener(EMMessageListener) to remove the message listener when it is not required.
listener | The message listener to add. See EMMessageListener. |
void com.hyphenate.chat.EMChatManager.asyncFetchConversationsFromServer | ( | final int | limit, |
final String | cursor, | ||
final EMValueCallBack< EMCursorResult< EMConversation > > | callback | ||
) |
Gets the list of conversations from the server with pagination.
The SDK retrieves the list of conversations in the reverse chronological order of their active time (generally the timestamp of the last message).
If there is no message in the conversation, the SDK retrieves the list of conversations in the reverse chronological order of their creation time.
limit | The number of conversations that you expect to get on each page. The value range is [1,50]. |
cursor | The position from which to start to get data. If you pass in null or an empty string (""), the SDK retrieves conversations from the latest active one. |
callback | The query result EMCursorResult, including the cursor for getting data next time and the conversation list. For the last page, the return value of cursor is an empty string. |
void com.hyphenate.chat.EMChatManager.asyncFetchHistoryMessages | ( | String | conversationId, |
EMConversationType | type, | ||
int | pageSize, | ||
String | cursor, | ||
EMFetchMessageOption | option, | ||
final EMValueCallBack< EMCursorResult< EMMessage > > | callBack | ||
) |
/**
Uses the pagination to get the messages in the conversation from the server according to the message pulling parameter configuration class (EMFetchMessageOption
).
This is a asynchronous method.
conversationId | The conversation ID.
|
type | The conversation type. See EMConversationType. |
pageSize | The number of messages you expect to get on each page. The value range is [1,50]. |
cursor | The cursor position from which to start querying data. |
option | The parameter configuration class for querying historical messages. See EMFetchMessageOption. |
callBack | The result callback:
|
void com.hyphenate.chat.EMChatManager.asyncFetchPinnedConversationsFromServer | ( | final int | limit, |
final String | cursor, | ||
final EMValueCallBack< EMCursorResult< EMConversation > > | callback | ||
) |
Get the list of pinned conversations from the server with pagination.
The SDK returns pinned conversations in the reverse chronological order of their pinning.
limit | The number of conversations that you expect to get on each page. The value range is [1,50]. |
cursor | The position from which to start getting data. If you pass in null or an empty string (""), the SDK retrieves the pinned conversations from the latest pinned one. |
callback | The query result EMCursorResult, including the cursor for getting data next time and the list of pinned conversations. For the last page, the return value of cursor is an empty string. |
void com.hyphenate.chat.EMChatManager.asyncPinConversation | ( | final String | conversationId, |
boolean | isPinned, | ||
final EMCallBack | callback | ||
) |
Sets whether to pin a conversation.
conversationId | The conversation ID. |
isPinned | Whether to pin the conversation:
|
false
: No. The conversation is unpinned. callback | The callback for setting whether to pin the conversation. |
void com.hyphenate.chat.EMChatManager.asyncRecallMessage | ( | final EMMessage | message, |
final EMCallBack | callback | ||
) |
Recalls the sent message.
This is an asynchronous method.
message | The message object. |
callback | A object of the EMCallBack class. See EMCallBack. |
boolean com.hyphenate.chat.EMChatManager.deleteConversation | ( | String | username, |
boolean | deleteMessages | ||
) |
Deletes a conversation and its local messages from the local database.
username | The conversation ID. |
deleteMessages | Whether to delete the historical messages with the conversation.
|
true
: Yes.false
: No. void com.hyphenate.chat.EMChatManager.deleteConversationFromServer | ( | String | username, |
EMConversationType | type, | ||
boolean | isDeleteServerMessages, | ||
EMCallBack | deleteCallBack | ||
) |
Deletes the specified conversation and its historical messages from the server.
This is an asynchronous method.
username | The conversation ID. |
type | The conversation type. See EMConversationType. |
isDeleteServerMessages | Whether to delete the historical messages with the conversation.
|
deleteCallBack | The callback for the deletion of the conversation and its historical messages.
|
void com.hyphenate.chat.EMChatManager.downloadAttachment | ( | final EMMessage | msg | ) |
Downloads the message attachment.
You can also call this method if the attachment fails to be downloaded automatically.
msg | The ID of the message with the attachment to be downloaded. |
void com.hyphenate.chat.EMChatManager.downloadThumbnail | ( | final EMMessage | msg | ) |
Downloads the message thumbnail.
msg | The message with the thumbnail to be downloaded. Only the image messages and video messages have a thumbnail. |
Map< String, EMConversation > com.hyphenate.chat.EMChatManager.getAllConversations | ( | ) |
Gets all local conversations.
Conversations will be first retrieved from the memory. If no conversation is found, the SDK retrieves from the local database.
EMConversation com.hyphenate.chat.EMChatManager.getConversation | ( | String | id | ) |
Gets the conversation object by conversation ID.
The SDK will return null
if the conversation is not found.
id | The conversation ID. |
null
if the conversation is not found. EMConversation com.hyphenate.chat.EMChatManager.getConversation | ( | String | id, |
EMConversationType | type | ||
) |
Gets the conversation by conversation ID and type.
The SDK will return null
if the conversation is not found.
id | The conversation ID:
|
type | The conversation type. See EMConversationType |
null
if the conversation is not found. EMConversation com.hyphenate.chat.EMChatManager.getConversation | ( | String | username, |
EMConversationType | type, | ||
boolean | createIfNotExists | ||
) |
Gets the conversation object by user ID or group ID and conversation type.
username | The conversation ID:
|
type | The conversation type. See EMConversationType. |
createIfNotExists | Whether to create a conversation if the specified conversation is not found:
|
null
if the conversation is not found. EMConversation com.hyphenate.chat.EMChatManager.getConversation | ( | String | username, |
EMConversationType | type, | ||
boolean | createIfNotExists, | ||
boolean | isChatThread | ||
) |
Get conversation object by conversation id and conversation type.
If the conversation is not found, you can create a new object based on the value of CreateIFNotExists or an empty object.
username | The conversation ID.
|
type | The conversation type. See EMConversationType. |
createIfNotExists | Whether to create a conversation if the specified conversation is not found:
|
isChatThread | Whether to search for the chat thread conversation.
|
null
if the conversation is not found. List< EMConversation > com.hyphenate.chat.EMChatManager.getConversationsByType | ( | EMConversationType | type | ) |
Gets the list of conversations by conversation type.
type | The conversation type. See EMConversationType. |
EMMessage com.hyphenate.chat.EMChatManager.getMessage | ( | String | messageId | ) |
Gets the message by message ID.
messageId | The message ID. |
null
if the message does not exist. int com.hyphenate.chat.EMChatManager.getUnreadMessageCount | ( | ) |
Gets the unread message count.
void com.hyphenate.chat.EMChatManager.recallMessage | ( | EMMessage | message | ) | throws HyphenateException |
Recalls the sent message.
If the recipient is offline when the message is delivered and recalled, the recipient only receives the callback EMMessageListener#onMessageRecalled instead of the message.
This is a synchronous method and blocks the current thread.
message | The message instance. |
HyphenateException | A description of the exception. See EMError. |
void com.hyphenate.chat.EMChatManager.removeConversationListener | ( | EMConversationListener | listener | ) |
Removes the conversation listener.
After adding a conversation listener with addConversationListener(EMConversationListener), you can call this method to remove it when it is not required.
listener | The conversation listener to remove. |
void com.hyphenate.chat.EMChatManager.removeMessageListener | ( | EMMessageListener | listener | ) |
Removes the message listener.
After adding a message listener with addMessageListener(EMMessageListener), you can call this method to remove it when it is not required.
listener | The message listener to remove. |
|
protected |
Retrieves messages of a certain type in the conversation from the local database.
type | The message type. See Type. |
timeStamp | The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the timestamp included in them. |
maxCount | The maximum number of messages to retrieve each time. The value range is [1,400]. |
from | The user ID of the message sender in one-to-one chat or group chat. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation. |
direction | The message search direction. See EMConversation.EMSearchDirection.
|
Retrieves messages with keywords in the conversation in the local database.
keywords | The keywords for query. |
timeStamp | The starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the timestamp included in them. |
maxCount | The maximum number of messages to retrieve each time. The value range is [1,400]. |
from | The user ID of the message sender in one-to-one chat or group chat. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation. |
direction | The message search direction. See EMConversation.EMSearchDirection.
|
Deletes local historical messages with a Unix timestamp before a specified one.
timeStamp | The starting Unix timestamp in the message for query. This unit is millisecond. |
callback | The result callback. See EMCallBack. |
Reports an inappropriate message.
This is an asynchronous method.
msgId | The ID of the message to report. |
tag | The tag of the inappropriate message. You need to type a custom tag, like porn or ad . |
reportReason | The reporting reason. You need to type a specific reason. |
callBack | The result callback. See EMCallBack.
|
Reports an inappropriate message.
This is a synchronous method and blocks the current thread.
msgId | The ID of the inappropriate message. |
tag | The tag of the inappropriate message. You need to type a custom tag, like porn or ad . |
reportReason | The reporting reason. You need to type a specific reason. |
HyphenateException | A description of the exception. See EMError. 获取翻译服务支持的语言。 |
callBack | 结果回调,详见 EMCallBack。
|
Gets all languages supported by the translation service.
callBack | The result callback. See EMCallBack.
|
Translates a text message.
message | The message object for translation. |
languages | The list of target language codes. |
callBack | The result callback. See EMCallBack.
|
Adds a Reaction.
This is a synchronous method.
messageId | The message ID. |
reaction | The Reaction content. |
HyphenateException | A description of the exception. See EMError. |
Adds a Reaction.
This is an asynchronous method.
messageId | The message ID. |
reaction | The message Reaction to add. |
callback | The result callback which contains the error information if the method fails. See EMCallBack. |
Deletes a Reaction.
This is a synchronous method.
messageId | The message ID. |
reaction | The Reaction content to delete. |
HyphenateException | A description of the exception. See EMError. |
Deletes a Reaction.
This is an asynchronous method.
messageId | The message ID. |
reaction | The Reaction to delete. |
callback | The result callback which contains the error information if the method fails. See EMCallBack. |
Gets the list of Reactions.
This is a synchronous method.
messageIdList | The message ID. |
chatType | The conversation type. Only the one-to-one chats (EMMessage.ChatType#Chat and group chats (EMMessage.ChatType#GroupChat) are allowed. |
groupId | The group ID, which is invalid only for group chats. |
UserList
of EMMessageReaction
indicates the summary data, which only contains the information of the first three users. HyphenateException | A description of the exception. See EMError. |
Gets the list of Reactions.
This is an asynchronous method.
messageIdList | The message ID. |
chatType | The conversation type. Only one-to-one chats (EMMessage.ChatType#Chat and group chats (EMMessage.ChatType#GroupChat) are allowed. |
groupId | The group ID, which is valid only for group chats. |
callback | The Reaction list under the specified message ID. The UserList of EMMessageReaction indicates the summary data, which only contains the information of the first three users. |
Gets the Reaction details.
This is a synchronous method.
messageId | The message ID. |
reaction | The Reaction content. |
cursor | The cursor position from which to start querying data. |
pageSize | The number of Reactions you expect to get on each page. |
null
, all data is obtained. HyphenateException | A description of the exception, see EMError. |
Gets the Reaction details.
This is an asynchronous method.
messageId | The message ID. |
reaction | The Reaction content. |
cursor | The cursor position from which to start querying data. |
pageSize | The number of Reactions you expect to get on each page. |
callback | The query result EMCursorResult, which contains the cursor for the next query and EMMessageReaction list (only the first data entry is used). |
Unidirectionally removes historical message by message ID from the server.
conversationId | The conversation ID. |
type | The conversation type. |
msgIdList | The list of IDs of messages to be removed. |
callBack | The result callback which contains the error information if the method fails. See EMCallBack. |
Unidirectionally removes historical message by timestamp from the server.
conversationId | The conversation ID. |
type | The conversation type. |
beforeTimeStamp | The UNIX timestamp in millisecond. Messages with a timestamp smaller than the specified one will be removed. |
callBack | The result callback which contains the error information if the method fails. See EMCallBack. |
void com.hyphenate.chat.EMChatManager.saveMessage | ( | EMMessage | message | ) |
Saves the message to the memory and local database.
The command messages (type: Type#CMD, message body: EMCmdMessageBody) are not saved locally.
message | The message to store. |
void com.hyphenate.chat.EMChatManager.sendMessage | ( | final EMMessage | msg | ) |
Sends a message。
For a voice or image message or a message with an attachment, the SDK will automatically upload the attachment.
You can determine whether to upload the attachment to the chat sever by setting EMOptions#setAutoTransferMessageAttachments(boolean).
To listen for the message sending status, call EMMessage#setMessageStatusCallback(EMCallBack).
msg | The message object to be sent. Make sure to set the param. |
void com.hyphenate.chat.EMChatManager.setVoiceMessageListened | ( | EMMessage | message | ) |
Marks a voice message as listened.
message | The message object. |