SDKsAndroid
Create a rich-text message
Use createAdvancedTextMessage to create a rich-text message with structured entity ranges.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
text | String | Yes | Complete plain-text content of the rich-text message. |
richMessages | List<RichMessage> | Yes | List 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
- Local initialization: This method constructs a local
Messageinstance without triggering network requests or SDK events. - Sending the message: Pass the returned
Messageobject to Send a message to transmit it to a single chat or group chat.
Was this page helpful?