SDKsAndroid
Create a custom message
Use createCustomMessage to carry application-defined JSON content.
Construct a custom message object carrying application-specific business payloads. By passing structured JSON data, optional extension metadata, and a fallback preview description, you can build custom interactive components such as red packets, polls, business cards, and order updates.
Code example
String dataJson = "{\"action\":\"red_packet\",\"packetID\":\"rp_888\",\"amount\":100}";
String extensionJson = "{\"theme\":\"festive\"}";
String description = "[Received a red packet]";
Message message = OpenIMClient.getInstance().messageManager.createCustomMessage(
dataJson,
extensionJson,
description
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
data | String | Yes | The primary custom payload, typically a serialized JSON string. |
extension | String | No | Additional business extension metadata. Pass an empty string if not needed. |
description | String | Yes | Summary preview text displayed in the conversation list or push notifications. |
Return value
Returns the created Message object with contentType set to MessageType.CUSTOM.
State changes after the call
- Local initialization: Initializes the local
Messagestructure without sending data to the server. - Schema agreement: Senders and receivers should negotiate schema conventions and implement graceful degradation for unrecognized versions.
- Transmission: Call Send a message to deliver the message.
Was this page helpful?