Browse SDKs · Android
Platform
SDKsAndroidIncludes Enterprise features

Message overview

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

Copy

The Android SDK uses the Message model to represent an individual message. Creating, sending, receiving, querying, and updating message states are distinct stages in the messaging lifecycle: creating a Message object does not transmit it to the server, and a successful send callback indicates server ingestion, not immediate receipt by recipient clients.

Message lists use clientMsgID as the client-side deduplication and update key, combined with the conversation context to distinguish between single (C2C) and group chats. The Message entity itself does not store a conversationID; the conversation context is derived from the active conversation, query arguments, or message event context.

Message lifecycle stages

StageAndroid API or callbackDescription
CreateMessage construction methods (such as Create a text message)Constructs a local Message entity. Does not upload data to the server or trigger new-message callbacks.
SendSend a message or Send a message without OSS uploadPass recvUid for single chat or recvGid for group chat.
ReceiveOnAdvanceMsgListenerHandles incoming real-time, offline, and online messages, as well as revokes, deletions, and read receipts.
QueryHistory retrieval, search, or find-by-ID APIsRetrieves a point-in-time snapshot of stored messages; does not replace real-time event listeners.
UpdateRevoke, delete, modify, pin, read receipts, and local extension APIsUpdates individual messages via API callbacks, async events, and list re-queries.

Incoming message events are documented in detail on the Receive messages page. Applications should configure OnAdvanceMsgListener once within a shared messaging repository or service layer and dispatch updates to active UI controllers.

Message model fields

All creation, transmission, reception, and retrieval operations interact with Message objects. Common fields include:

FieldTypeDescription
clientMsgIDStringClient-generated unique message identifier, used for local deduplication and state updates.
serverMsgIDStringServer-assigned message ID. May be empty until the message is acknowledged by the server.
sessionTypeintSession type, used with recvID and groupID to determine single or group chat.
sendIDStringSender user ID.
recvIDStringRecipient user ID for single chat conversations.
groupIDStringGroup ID for group chat conversations.
msgFromintDistinguishes between user-generated and system-generated messages.
contentTypeintMessage content type, matching constants in MessageType.
createTimelongTimestamp in nanoseconds when the message object was created.
sendTimelongTimestamp in milliseconds when the message was sent.
seqintServer-assigned sequence number.
statusintMessage delivery status, matching constants in MessageStatus.
isReadbooleanLocal read status on the current client.
platformIDintPlatform identifier of the sending client.
senderNicknameStringSender nickname recorded when the message was created or sent.
senderFaceUrlStringSender avatar URL recorded when the message was created or sent.
offlinePushOfflinePushInfoPush notification configuration for offline recipients.
attachedInfoStringSDK internal attachment string.
extObjectAdditional message extension attributes.
exObjectCustom business extension attributes.
localExObjectLocal extension attributes persisted only on the local device.

Message content payloads are stored in specific element fields corresponding to contentType:

Content typeElement field
Text, rich texttextElem, advancedTextElem
Image, sound, video, filepictureElem, soundElem, videoElem, fileElem
@ mentions, repliesatTextElem, quoteElem
Merged forwardmergeElem
Contact card, location, custom facescardElem, locationElem, faceElem
Custom business messagecustomElem
Notifications, typing indicator, attached statusnotificationElem, typingElem, attachedInfoElem

Creating and sending messages

Sending any message requires two steps:

  1. Call the corresponding message creation method (such as Create a text message) to generate a Message object.
  2. Pass the Message instance to Send a message, specifying recvUid for single chat or recvGid for group chat.

Supported message creation guides:

When sending media messages initialized from a local file path, use Send a message so the SDK automatically uploads the binary payload. When creating media messages with pre-uploaded remote URLs, use the corresponding URL creation method and send with Send a message without OSS upload to skip redundant file uploads.

Common messaging tasks

State synchronization model

State changeEvent / CallbackSynchronization approach
New and offline messagesReceive messagesDetermine the conversation context, then deduplicate and insert by clientMsgID.
Message revocationonRecvMessageRevokedV2Update the revoked message state in-place using the message ID from the revoke payload.
Message deletiononMsgDeletedEnterpriseRemove the matching message from the local UI cache using clientMsgID.
C2C and group read receiptsonRecvC2CReadReceipt, onRecvGroupMessageReadReceiptEnterpriseUpdate the read status and reader counts for matching messages.
Message extension updatesonRecvMessageExtensionsChangedUpdate the extension fields for the targeted message ID without replacing the message body.
Typing indicatorUpdate typing statusMaintain transient typing state per conversation without inserting into the message list.

Always process the immediate API callback result before waiting for listener events from OnAdvanceMsgListener. When local caches diverge after reconnection, re-query the message list to calibrate state.