Browse SDKs · Android
Platform
SDKsAndroid

Set local message extensions

Use setMessageLocalEx to store message data used only on the current device.

Copy

Save device-specific custom extension data (localEx) for a designated message on the current device. This is suitable for caching local file download states, media playback timestamps, audio transcription text caches, or custom UI display attributes. The stored data remains strictly local and is never synchronized to the server or other client devices.

Code example

String conversationID = "si_user_a_user_b";
String clientMsgID = "msg_001";
String localExJson = "{\"downloadStatus\":2,\"localPath\":\"/storage/emulated/0/...\"}";

OpenIMClient.getInstance().messageManager.setMessageLocalEx(
    new OnBase<String>() {
        @Override
        public void onSuccess(String data) {
            // Local extension saved successfully
        }

        @Override
        public void onError(int code, String error) {
            // Handle save failure
        }
    },
    conversationID,
    clientMsgID,
    localExJson
);

Parameters

ParameterTypeRequiredDescription
baseOnBase<String>YesCallback handler for the asynchronous request.
conversationIDStringYesGlobally unique ID of the conversation containing the message.
clientMsgIDStringYesClient message ID of the target message.
localExStringYesCustom extension string (typically formatted as JSON).

Return value

Upon success, data in onSuccess returns a confirmation message.

State changes after the call

  1. Callback confirmation: The onSuccess callback confirms that localEx was updated in the local database. Update the localEx property on the in-memory message instance using clientMsgID and refresh the UI item.
  2. Local scope: This operation writes strictly to local storage. It does not alter message body content on the server and does not trigger real-time events on other clients.
  3. Re-query calibration: The extension persists only in local storage on this device and will not be present if the message is re-fetched from cloud roaming history on another device.