Browse SDKs · Android
Platform
SDKsAndroid

Insert a local group message

Use insertGroupMessageToLocalStorage to insert a group message visible only on the current device.

Copy

Write a pre-constructed message directly into the local SQLite database of the current device for a group conversation. This operation does not issue a network request to the server, does not dispatch messages to other group members, and does not persist to cloud storage. It is suitable for displaying group join safety notices, local event announcements, or device-specific system logs. To send an actual message to all group members across the network, call Send a message.

Code example

String groupID = "group_123";
String senderUserID = "user_a";

OpenIMClient.getInstance().messageManager.insertGroupMessageToLocalStorage(
    new OnBase<String>() {
        @Override
        public void onSuccess(String data) {
            // Message written to local storage, refresh group chat UI
        }

        @Override
        public void onError(int code, String error) {
            // Handle insertion failure
        }
    },
    message,
    groupID,
    senderUserID
);

Parameters

ParameterTypeRequiredDescription
baseOnBase<String>YesCallback handler for the asynchronous request.
messageMessageYesPre-constructed message object (typically created via one of the create*Message APIs).
groupIDStringYesGlobally unique ID of the target group.
senderStringYesUser ID designated as the sender of the message.

Return value

Upon success, data in onSuccess returns a confirmation message.

State changes after the call

  1. Callback confirmation: The onSuccess callback confirms that the message record was written to the local database. Insert the message into your group chat UI timeline using clientMsgID.
  2. Local scope: This is a local-only operation that does not persist to the server, does not dispatch to other group members, and does not fire OnAdvanceMsgListener.onRecvNewMessage events.
  3. Re-query calibration: The message exists only on the current device. It will not synchronize across devices logged into the same account or appear in cloud roaming history.