IMSDK
IM features a comprehensive suite of solutions including global access, one-to-one chat, group chat, message push, profile and relationship chain hosting, and account authentication. It also provides complete app access and backend management APIs.
V2TIMMessageManagerabstract

Public Member Functions

abstract void addAdvancedMsgListener (V2TIMAdvancedMsgListener listener)
 
abstract void removeAdvancedMsgListener (V2TIMAdvancedMsgListener listener)
 
abstract V2TIMMessage createTextMessage (String text)
 
abstract V2TIMMessage createTextAtMessage (String text, List< String > atUserList)
 
abstract V2TIMMessage createCustomMessage (byte[] data)
 
abstract V2TIMMessage createCustomMessage (byte[] data, String description, byte[] extension)
 
abstract V2TIMMessage createImageMessage (String imagePath)
 
abstract V2TIMMessage createSoundMessage (String soundPath, int duration)
 
abstract V2TIMMessage createVideoMessage (String videoFilePath, String type, int duration, String snapshotPath)
 
abstract V2TIMMessage createFileMessage (String filePath, String fileName)
 
abstract V2TIMMessage createLocationMessage (String desc, double longitude, double latitude)
 
abstract V2TIMMessage createFaceMessage (int index, byte[] data)
 
abstract V2TIMMessage createMergerMessage (List< V2TIMMessage > messageList, String title, List< String > abstractList, String compatibleText)
 
abstract V2TIMMessage createForwardMessage (V2TIMMessage message)
 
abstract String sendMessage (V2TIMMessage message, String receiver, String groupID, int priority, boolean onlineUserOnly, V2TIMOfflinePushInfo offlinePushInfo, V2TIMSendCallback< V2TIMMessage > callback)
 
abstract void setC2CReceiveMessageOpt (List< String > userIDList, int opt, V2TIMCallback callback)
 
abstract void getC2CReceiveMessageOpt (List< String > userIDList, V2TIMValueCallback< List< V2TIMReceiveMessageOptInfo >> callback)
 
abstract void setGroupReceiveMessageOpt (String groupID, int opt, V2TIMCallback callback)
 
abstract void getC2CHistoryMessageList (String userID, int count, V2TIMMessage lastMsg, V2TIMValueCallback< List< V2TIMMessage >> callback)
 
abstract void getGroupHistoryMessageList (String groupID, int count, V2TIMMessage lastMsg, V2TIMValueCallback< List< V2TIMMessage >> callback)
 
abstract void getHistoryMessageList (V2TIMMessageListGetOption option, V2TIMValueCallback< List< V2TIMMessage >> callback)
 
abstract void revokeMessage (V2TIMMessage msg, V2TIMCallback callback)
 
abstract void markC2CMessageAsRead (String userID, V2TIMCallback callback)
 
abstract void markGroupMessageAsRead (String groupID, V2TIMCallback callback)
 
abstract void markAllMessageAsRead (V2TIMCallback callback)
 
abstract void deleteMessageFromLocalStorage (V2TIMMessage msg, V2TIMCallback callback)
 
abstract void deleteMessages (List< V2TIMMessage > messages, V2TIMCallback callback)
 
abstract void clearC2CHistoryMessage (String userID, V2TIMCallback callback)
 
abstract void clearGroupHistoryMessage (String groupID, V2TIMCallback callback)
 
abstract String insertGroupMessageToLocalStorage (V2TIMMessage msg, String groupID, String sender, V2TIMValueCallback< V2TIMMessage > callback)
 
abstract String insertC2CMessageToLocalStorage (V2TIMMessage msg, String userID, String sender, V2TIMValueCallback< V2TIMMessage > callback)
 
abstract void findMessages (List< String > messageIDList, V2TIMValueCallback< List< V2TIMMessage >> callback)
 
abstract void searchLocalMessages (V2TIMMessageSearchParam searchParam, V2TIMValueCallback< V2TIMMessageSearchResult > callback)
 

Member Function Documentation

◆ addAdvancedMsgListener()

abstract void addAdvancedMsgListener ( V2TIMAdvancedMsgListener  listener)
abstract

1.1 Add an event listener for advanced messages

◆ removeAdvancedMsgListener()

abstract void removeAdvancedMsgListener ( V2TIMAdvancedMsgListener  listener)
abstract

1.2 Remove the event listener for advanced messages

◆ createTextMessage()

abstract V2TIMMessage createTextMessage ( String  text)
abstract

2.1 Create a text message

◆ createTextAtMessage()

abstract V2TIMMessage createTextAtMessage ( String  text,
List< String >  atUserList 
)
abstract

2.2 Create a text message with the @ notification feature

Notification messages are only applicable to messages sent in the group.

Parameters
atUserListList of @ target users. To @all, please pass in the AT_ALL_TAG constant string. For example, if you want the current text message to @denny, @lucy, and @all, pass in ["denny","lucy",AT_ALL_TAG] for atUserList.
Attention
The following are use limits for atUserList:
  • The maximum number of @ target users is 30 by default. If this limit is exceeded, message sending will fail.
  • The total number of users specified by atUserList cannot exceed the default maximum number, including the case of @all.

◆ createCustomMessage() [1/2]

abstract V2TIMMessage createCustomMessage ( byte[]  data)
abstract

2.3 Create a custom message

◆ createCustomMessage() [2/2]

abstract V2TIMMessage createCustomMessage ( byte[]  data,
String  description,
byte[]  extension 
)
abstract

2.4 Create a custom message and set offline push information

Parameters
descriptionCustom message description information to be displayed in text during offline push
extensionExtension field information during offline push

◆ createImageMessage()

abstract V2TIMMessage createImageMessage ( String  imagePath)
abstract

2.5 Create an image message (image size limit: 28 MB)

◆ createSoundMessage()

abstract V2TIMMessage createSoundMessage ( String  soundPath,
int  duration 
)
abstract

2.6 Create a voice message (voice size limit: 28 MB)

Parameters
durationVoice duration, in seconds

◆ createVideoMessage()

abstract V2TIMMessage createVideoMessage ( String  videoFilePath,
String  type,
int  duration,
String  snapshotPath 
)
abstract

2.7 Create a video message (video size limit: 100 MB)

Parameters
typeVideo type, such as mp4 and mov
durationVideo duration, in seconds
snapshotPathVideo cover image path

◆ createFileMessage()

abstract V2TIMMessage createFileMessage ( String  filePath,
String  fileName 
)
abstract

2.8 Create a file message (file size limit: 100 MB)

◆ createLocationMessage()

abstract V2TIMMessage createLocationMessage ( String  desc,
double  longitude,
double  latitude 
)
abstract

2.9 Create a location message

◆ createFaceMessage()

abstract V2TIMMessage createFaceMessage ( int  index,
byte[]  data 
)
abstract

2.10 Create an emoji message

The IM SDK does not provide an emoji package. Developers can use index to store the indexes of the emojis they have in their emoji packages. Alternatively, they can directly use data to store emoji binary data and the string key. Either way, developers can customize emojis. The IM SDK is only responsible for passing them through.

Parameters
indexEmoji index
dataCustom data

◆ createMergerMessage()

abstract V2TIMMessage createMergerMessage ( List< V2TIMMessage messageList,
String  title,
List< String >  abstractList,
String  compatibleText 
)
abstract

2.11 Create a combined message (supported only in 5.2.210 and later versions)

Usually when we receive a combined message, the chat screen will look like this:

|Chat History of Vinson and Lynx | – title (Title)

|Vinson: When is the new version of SDK scheduled to go online? | – abstract1 (Digest information 1)

|Lynx: Next Monday. The specific time depends on the system test result in these two days. | – abstract2 (Digest information 2)

|Vinson: OK | – abstract3 (Digest information 3)

The chat UI usually displays only the title and digest information of the combined message, and the complete combined message list will be displayed only when the user clicks the combined message on the UI.

You can create a combined message (V2TIMMessage) for multiple messages to be forwarded and call the sendMessage API to send the combined message. The procedure is as follows:

1. Call createMergerMessage to create a combined message V2TIMMessage.

2. Call sendMessage to send the forward message V2TIMMessage.

The procedure for parsing a combined message received is as follows:

1. Obtain mergerElem via V2TIMMessage.

2. Obtain title and abstractList via mergerElem for UI display.

3. When a user clicks the digest information on the UI, call downloadMessageList to get the list of forwarded messages.

Parameters
messageListMessage list (Up to 300 messages are supported. The message object must be in the V2TIM_MSG_STATUS_SEND_SUCC status. The message type cannot be V2TIMGroupTipsElem.)
titleSource of the combined message, for example, "Chat History of Vinson and Lynx" and "xxx group chat history"
abstractListCombined message digest list (supports up to 5 digests, each containing a maximum of 100 characters) You can set digest information in different formats for different message types, for example: For a text message, the digest can be in the "sender:text" format. For an image message, the digest can be in the "sender:[image]" format. For a file message, the digest can be in the "sender:[file]" format.
compatibleTextCombined messages are compatible with text. SDKs of early versions do not support combined messages, and they will send a text message with the content compatibleText by default. The parameter cannot be null.

◆ createForwardMessage()

abstract V2TIMMessage createForwardMessage ( V2TIMMessage  message)
abstract

2.12 Create a forward message (supported only in 5.2.210 and later versions)

If you need to forward a message, you cannot directly call the sendMessage API to send the original message. Instead, you need to call createForwardMessage to create a forward message first and send it.

Parameters
messageMessage object to be forwarded. The message status must be V2TIM_MSG_STATUS_SEND_SUCC. The message type cannot be V2TIMGroupTipsElem.
Returns
Forward message object. The elem content is the same as the original message.

◆ sendMessage()

abstract String sendMessage ( V2TIMMessage  message,
String  receiver,
String  groupID,
int  priority,
boolean  onlineUserOnly,
V2TIMOfflinePushInfo  offlinePushInfo,
V2TIMSendCallback< V2TIMMessage callback 
)
abstract

3.1 Send an advanced message (advanced version: provides the features of specifying message priorities and push information)

Parameters
messageMessage object to be sent, which needs to be created via the corresponding message creation API
receiverMessage recipient's userID. For a one-to-one message, you only need to specify this field.
groupIDTarget group ID For a group chat message, you only need to specify this field.
priorityMessage priorities. This field is valid only for group chat messages. You are advised to set higher priorities for important messages (such as red packet and gift messages) and set lower priorities for frequent but unimportant messages (such as like messages).
onlineUserOnlyWhether the message can be received only by online users. If this field is set to true, the message cannot be pulled in recipient historical message pulling. This field is often used to implement weak notification features such as "The other party is typing" or unimportant notifications in the group. This field is not supported by audio-video groups (AVChatRoom).
offlinePushInfoTitle and content for offline push
Returns
Unique ID of the message
Attention
  • Before setting the offlinePushInfo field, you need to enable push via V2TIMOfflinePushManager. After push is enabled, all messages except custom messages will be pushed by default.
  • If you want to push custom messages as well, set the desc field in offlinePushInfo so that the information specified by desc will be displayed by default during push.
  • Audio-video groups (AVChatRoom) do not support the onlineUserOnly field. You need to set onlineUserOnly to false for audio-video groups (AVChatRoom).
  • If onlineUserOnly is set to true, the message is an online message and is not counted as an unread message.

◆ setC2CReceiveMessageOpt()

abstract void setC2CReceiveMessageOpt ( List< String >  userIDList,
int  opt,
V2TIMCallback  callback 
)
abstract

4.1 Set the one-to-one message receiving option for specified users (batch setting supported)

Supported only in 5.3.425 and later versions.

Attention
Notes:
  • This API supports batch setting. You can use the userIDList field to specify up to 30 users for batch setting.
  • This API can be called for up to 5 times per second.
Parameters
optThere are three message receiving options: V2TIMMessage.V2TIM_RECEIVE_MESSAGE: messages will be received when the user is online, and push notifications will be received when the user is offline. V2TIMMessage.V2TIM_NOT_RECEIVE_MESSAGE: no message will be received. V2TIMMessage.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE: messages will be received when the user is online, and no push notification will be received when the user is offline.

◆ getC2CReceiveMessageOpt()

abstract void getC2CReceiveMessageOpt ( List< String >  userIDList,
V2TIMValueCallback< List< V2TIMReceiveMessageOptInfo >>  callback 
)
abstract

4.2 Query the one-to-one message receiving option for specified users

Supported only in 5.3.425 and later versions.

◆ setGroupReceiveMessageOpt()

abstract void setGroupReceiveMessageOpt ( String  groupID,
int  opt,
V2TIMCallback  callback 
)
abstract

4.3 Set the group message receiving option

Parameters
optThere are three message receiving options: V2TIMMessage.V2TIM_RECEIVE_MESSAGE: messages will be received when the user is online, and push notifications will be received when the user is offline. V2TIMMessage.V2TIM_NOT_RECEIVE_MESSAGE: no group message will be received. V2TIMMessage.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE: messages will be received when the user is online, and no push notification will be received when the user is offline.

◆ getC2CHistoryMessageList()

abstract void getC2CHistoryMessageList ( String  userID,
int  count,
V2TIMMessage  lastMsg,
V2TIMValueCallback< List< V2TIMMessage >>  callback 
)
abstract

5.1 Get historical one-to-one messages

Parameters
countNumber of messages pulled at a time. The value of this field cannot be too large; otherwise, the pulling speed is affected. We recommend that you pull 20 messages at a time.
lastMsgStart message for message pulling. If null is passed in, the newest message of the conversation will be considered as the start message.
Attention
If the IM SDK detects that the network connection is unavailable, it directly returns local data.

◆ getGroupHistoryMessageList()

abstract void getGroupHistoryMessageList ( String  groupID,
int  count,
V2TIMMessage  lastMsg,
V2TIMValueCallback< List< V2TIMMessage >>  callback 
)
abstract

5.2 Get historical group messages

Parameters
countNumber of messages pulled at a time. The value of this field cannot be too large; otherwise, the pulling speed is affected. We recommend that you pull 20 messages at a time.
lastMsgStart message for message pulling. If null is passed in, the newest message of the conversation will be considered as the start message.
Attention
Notes:
  • If the IM SDK detects that the network connection is unavailable, it directly returns local data.
  • Only meeting groups (Meeting) support pulling historical messages of members before they join the groups. For audio-video groups (AVChatRoom), messages are not saved to the roaming and local databases, and therefore this API does not take effect.

◆ getHistoryMessageList()

abstract void getHistoryMessageList ( V2TIMMessageListGetOption  option,
V2TIMValueCallback< List< V2TIMMessage >>  callback 
)
abstract

5.3 Get historical messages (advanced API)

Parameters
optionMessage pulling option, which can be set to pull older or newer messages from local storage or the cloud
Attention
Notes:
  • If option is set to pull messages from the cloud, and the IM SDK detects that the network connection is unavailable, the IM SDK directly returns local data.
  • Only meeting groups (Meeting) support pulling historical messages of members before they join the groups. For audio-video groups (AVChatRoom), messages are not saved to the roaming and local databases, and therefore this API does not take effect.

◆ revokeMessage()

abstract void revokeMessage ( V2TIMMessage  msg,
V2TIMCallback  callback 
)
abstract

5.4 Recall messages

Attention
Notes:
  • By default, you can recall only messages that are sent within 2 minutes. You can customize the time limit for message recall via the console (Feature Configuration -> Login and Message -> Message Recall Settings).
  • Only common messages sent in one-to-one chats and group chats can be recalled. Messages that can be received only by online users (onlineUserOnly is set to true) and audio-video group (AVChatRoom) messages cannot be recalled.
  • If the sender recalls a message, the recipient will receive the V2TIMAdvancedMsgListener -> onRecvMessageRevoked callback.

◆ markC2CMessageAsRead()

abstract void markC2CMessageAsRead ( String  userID,
V2TIMCallback  callback 
)
abstract

5.5 Mark one-to-one messages as read

Attention
If the userID is null, all one-to-one messages wil be marked as read. More importantly, it only supported in 5.8 and later versions.

◆ markGroupMessageAsRead()

abstract void markGroupMessageAsRead ( String  groupID,
V2TIMCallback  callback 
)
abstract

5.6 Mark group messages as read

Attention
If the groupID is null, all group messages wil be marked as read. More importantly, it only supported in 5.8 and later versions.

◆ markAllMessageAsRead()

abstract void markAllMessageAsRead ( V2TIMCallback  callback)
abstract

5.7 Mark all messages as read(Supported only in 5.8 and later versions)

◆ deleteMessageFromLocalStorage()

abstract void deleteMessageFromLocalStorage ( V2TIMMessage  msg,
V2TIMCallback  callback 
)
abstract

5.8 Delete a message from local storage

Attention
Messages can only be deleted locally. After a message is deleted, the SDK marks the message as deleted locally, and the message can no longer be pulled via getHistoryMessage. However, after the app is uninstalled and reinstalled, the local delete marker of the message will get lost, and the message can still be pulled via getHistoryMessage.

◆ deleteMessages()

abstract void deleteMessages ( List< V2TIMMessage messages,
V2TIMCallback  callback 
)
abstract

5.9 Delete messages from local storage and the cloud

Attention
In addition to deleting messages from the local storage (deleteMessageFromLocalStorage), this API simultaneously deletes messages from the cloud, and the deleted messages cannot be recovered. Please note that:
  • Up to 30 messages can be deleted at a time.
  • The messages to be deleted at a time must belong to the same conversation.
  • This API can be called only once per second.
  • If the account has pulled these messages from other devices, the messages will still be stored on those devices after this API is called to delete them. That is, the operation of message deletion cannot be synchronized across multiple devices.

◆ clearC2CHistoryMessage()

abstract void clearC2CHistoryMessage ( String  userID,
V2TIMCallback  callback 
)
abstract

5.10 Clear chat history with a user from local storage and the cloud (without deleting the conversation)

Supported only in 5.4.666 and later versions.

Attention
Notes:
  • When messages in a conversation are deleted from local storage, they are deleted simultaneously from the server.

◆ clearGroupHistoryMessage()

abstract void clearGroupHistoryMessage ( String  groupID,
V2TIMCallback  callback 
)
abstract

5.11 Clear chat history of a group from local storage and the cloud (without deleting the conversation)

Supported only in 5.4.666 and later versions.

Attention
Notes:
  • When messages in a conversation are deleted from local storage, they are also deleted from the server.

◆ insertGroupMessageToLocalStorage()

abstract String insertGroupMessageToLocalStorage ( V2TIMMessage  msg,
String  groupID,
String  sender,
V2TIMValueCallback< V2TIMMessage callback 
)
abstract

5.12 Add a message to the group message list

This API is mainly used to meet the requirement of inserting informative messages, such as "you have exited the group", into a group chat conversation. Such messages need to be displayed in the chat interface but do not need to be sent to others. Messages that need to be displayed in the chat interface but do not need to be sent to others. Therefore, insertGroupMessageToLocalStorage() is equivalent to a sendMessage() API whose network sending capability is disabled.

Returns
msgID Unique ID of a message
Attention
Messages saved via this API are saved only to the local storage and will get lost after the app is uninstalled.

◆ insertC2CMessageToLocalStorage()

abstract String insertC2CMessageToLocalStorage ( V2TIMMessage  msg,
String  userID,
String  sender,
V2TIMValueCallback< V2TIMMessage callback 
)
abstract

5.13 Insert a message in a one-to-one chat

This API is mainly used to meet the requirement of inserting informative messages, such as "you have exited the group", into a one-to-one chat conversation. Such messages need to be displayed in the chat interface but do not need to be sent to the peer party. Messages that need to be displayed in the chat interface but do not need to be sent to others. Therefore, insertC2CMessageToLocalStorage() is equivalent to a sendMessage() API whose network sending capability is disabled.

Returns
msgID Unique ID of a message
Attention
Messages saved via this API are saved only to the local storage and will get lost after the app is uninstalled.

◆ findMessages()

abstract void findMessages ( List< String >  messageIDList,
V2TIMValueCallback< List< V2TIMMessage >>  callback 
)
abstract

5.14 Query local messages in a specified conversation by messageID

Parameters
messageIDListMessage ID list

◆ searchLocalMessages()

abstract void searchLocalMessages ( V2TIMMessageSearchParam  searchParam,
V2TIMValueCallback< V2TIMMessageSearchResult callback 
)
abstract

5.15 Search for local messages (supported only in 5.4.666 and later versions and need to buy Flagship Edition)

Parameters
searchParamMessage search parameter. For details, see the definition of V2TIMMessageSearchParam.