Browse SDKs · Android
SDKsAndroid

Insert a local direct message

Use insertSingleMessageToLocalStorage to insert a one-to-one message visible only on the current device.

Copy

insertSingleMessageToLocalStorage() writes a message to a one-to-one chat on the current device. Use it for imported records or application notices that must remain local. It does not send the message to the server.

message is the complete message object, receiver is the recipient user ID, and sender is the sender user ID. These two IDs determine the message direction and are not interchangeable.

OpenIMClient.getInstance().messageManager.insertSingleMessageToLocalStorage(
    new OnBase<String>() {
        @Override
        public void onSuccess(String data) {
            // Re-read or update the one-to-one message list on this device.
        }

        @Override
        public void onError(int code, String error) {
            // Report the local write failure.
        }
    },
    message,
    receiverUserID,
    senderUserID
);

The success callback means the local write completed. This operation does not trigger a new-message event and cannot replace Send a message.