Browse SDKs · Android
SDKsAndroid

Message overview

Learn about the Android SDK Message model, message lifecycle, and message listener.

Copy

The Android SDK represents each message as Message. Message creation, sending, receiving, querying, and state changes are separate stages: creating a Message does not send it, and a successful send does not mean that other clients have already received it.

Use clientMsgID as the client-side deduplication and update key, together with the conversation context that identifies a one-to-one or group chat. Message does not contain conversationID; obtain it from the active conversation, history query, or message event context.

Message processing flow

StageAndroid API or callbackDescription
CreateMessageManager.create*Message()Creates a Message object ready to be sent, without writing it to the server or triggering a new-message callback.
SendsendMessage() or sendMessageNotOss()Pass recvUid for a one-to-one chat or recvGid for a group chat.
ReceiveOnAdvanceMsgListenerHandles live, offline, online-only, revoked, deleted, and read-receipt changes.
QueryHistory, ID lookup, or search APIsQueries return the messages read by that request and do not replace real-time message listening.
UpdateRevoke, delete, modify, pin, read, and local-extension APIsHandle API results, related events, and any necessary list re-query separately.

Receive messages is the owning page for message events. Set OnAdvanceMsgListener once in the shared message state layer, then dispatch new, offline, revoked, and deleted message changes to screens. This overview does not register the listener again.

Message fields

The message object returned by creation, sending, receiving, and querying APIs is a Message. Common fields include:

FieldTypeDescription
clientMsgIDStringClient message ID used for list deduplication, state updates, and message lookup.
serverMsgIDStringServer message ID; it may not have a valid value before a message is sent successfully.
sessionTypeintConversation type; use it with recvID and groupID to distinguish one-to-one and group chats.
sendIDStringSender user ID.
recvIDStringRecipient user ID for a one-to-one message.
groupIDStringGroup ID for a group message.
msgFromintIndicates whether the message is user-level or system-level.
contentTypeintMessage type; use MessageType constants to select the content field.
createTimelongMessage creation time; the Android model documents this value in nanoseconds.
sendTimelongMessage send time; the Android model documents this value in milliseconds.
seqintServer message sequence number.
statusintSend state; use MessageStatus constants to interpret it.
isReadbooleanRead-state snapshot stored on the current client.
platformIDintClient platform from which the message was sent.
senderNicknameStringSnapshot of the sender's nickname.
senderFaceUrlStringSnapshot of the sender's avatar URL.
isReactbooleanWhether the message carries a reaction marker.
isExternalExtensionsbooleanWhether the message uses external extensions.
offlinePushOfflinePushInfoOffline-push content.
attachedInfoStringSDK attachment information.
extObjectAndroid message attachment field.
exObjectMessage attachment field.
localExObjectMessage extension field stored only on the current device.

The message body is stored in the element field selected by contentType. Do not infer the message type from list position or rendered text:

Message contentCorresponding field
Text and rich texttextElem, advancedTextElem
Image, audio, video, and filepictureElem, soundElem, videoElem, fileElem
@ mention and replyatTextElem, quoteElem
Merged forwardmergeElem
Contact card, location, and emojicardElem, locationElem, faceElem
Custom messagecustomElem
Notification, typing, and attached statenotificationElem, typingElem, attachedInfoElem

Create and send different content types

Sending a message has two steps:

  1. Call the create*Message() method for the desired content to obtain a pending Message.
  2. Pass that Message to Send a message. For a one-to-one chat, set recvUid; for a group chat, set recvGid.

The available message types and creation methods are:

Choose the send method based on the media source. For a message created from a local path or local file, call sendMessage() so the SDK uploads the media during sending. For a message created from an existing remote URL with create*MessageByURL(), follow Send an uploaded media message to avoid uploading it again.

Find a page by task

TaskPage
Send an ordinary message or already-uploaded mediaSend a message, Send an uploaded media message
Receive live, offline, and online-only messagesReceive messages, Receive custom business messages
Load message history or load it in reverseLoad message history, Load message history in reverse
Locate or search messagesFind messages by ID, Search messages
Delete, revoke, modify, or pin messagesDelete messages, Revoke a message, Modify a message, Pin a message
Manage conversation unread state and group read receiptsMark a conversation as read, Report group messages as read, Get group message readers
Report or retrieve typing statusUpdate typing status, Get typing status
Insert, delete, or extend current-device-only messagesInsert a local one-to-one message, Delete a local message, Set a local message extension

State synchronization boundaries

ChangeHandling locationMerge strategy
New and offline messagesReceive messagesDetermine the target conversation, then merge by clientMsgID.
Message revocationonRecvMessageRevokedV2Update the original message by the ID in the revoke information.
Message deletiononMsgDeletedRemove the message from the current conversation by ID.
C2C and group read receiptsonRecvC2CReadReceipt, onRecvGroupMessageReadReceiptUpdate the corresponding message or conversation read state.
Message extension changesonRecvMessageExtensionsChanged and related callbacksUpdate extension fields by message ID without replacing the message body.
Typing statusUpdate typing statusMaintain temporary state by conversation and user, outside the ordinary message list.

For message revocation, deletion, read receipts, and extension changes, handle the API result first, then process the related OnAdvanceMsgListener callbacks. Re-query the message list when necessary.