SDKsAndroid
Insert a local direct message
Use insertSingleMessageToLocalStorage to insert a one-to-one message visible only on the current device.
Write a pre-constructed message directly into the local SQLite database of the current device for a one-to-one conversation. This operation does not issue a network request to the server, does not deliver the message to the peer user, and does not synchronize to other devices logged into the same account. It is commonly used for inserting local security prompts, client-side assistant messages, or migrating offline records. To send an actual message across the network, call Send a message.
Code example
String receiverUserID = "user_b";
String senderUserID = "user_a";
OpenIMClient.getInstance().messageManager.insertSingleMessageToLocalStorage(
new OnBase<String>() {
@Override
public void onSuccess(String data) {
// Message written to local storage, refresh direct chat UI
}
@Override
public void onError(int code, String error) {
// Handle insertion failure
}
},
message,
receiverUserID,
senderUserID
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
base | OnBase<String> | Yes | Callback handler for the asynchronous request. |
message | Message | Yes | Pre-constructed message object (typically created via one of the create*Message APIs). |
receiver | String | Yes | User ID of the direct chat recipient. |
sender | String | Yes | User ID of the direct chat sender. These two fields determine message direction and must not be inverted. |
Return value
Upon success, data in onSuccess returns a confirmation message.
State changes after the call
- Callback confirmation: The
onSuccesscallback confirms that the message was saved to local storage on this device. Insert the item into your conversation timeline usingclientMsgIDas the distinct key. - Local scope: This is a local-only operation that does not trigger network requests or dispatch
OnAdvanceMsgListener.onRecvNewMessageevents. - Re-query calibration: The inserted message exists only in the local database on this device. It will not synchronize to cloud roaming history or appear on other devices logged into the same account.
Was this page helpful?