Browse SDKs · Android
Platform
SDKsAndroid

Create a rich-text message

Use createAdvancedTextMessage to create a rich-text message with structured entity ranges.

Copy

Construct a message object containing structured rich-text entities (such as hyperlinks, custom tags, or mentions). By defining a list of RichMessage entities with character offsets (offset) and span lengths (length), recipient clients can highlight text spans and bind click actions.

Code example

RichMessage link = new RichMessage();
link.setType("link");
link.setOffset(0);
link.setLength(6);
link.setUrl("https://docs.openim.io");
link.setInfo("{\"title\":\"OpenIM documentation\"}");

Message message = OpenIMClient.getInstance().messageManager.createAdvancedTextMessage(
    "OpenIM documentation link",
    Collections.singletonList(link)
);

Parameters

ParameterTypeRequiredDescription
textStringYesComplete plain-text content of the rich-text message.
richMessagesList<RichMessage>YesList of structured rich-text entities. Each entity specifies type (entity type), offset (starting character index), length (span length), url (target URL), and info (custom metadata).

Return value

Returns the created Message object with contentType set to MessageType.ADVANCED_TEXT.

State changes after the call

  1. Local initialization: This method constructs a local Message instance without triggering network requests or SDK events.
  2. Sending the message: Pass the returned Message object to Send a message to transmit it to a single chat or group chat.