Browse SDKs · Android
Platform
SDKsAndroidEnterprise

Pin or unpin a message

Change a conversation message’s pinned state and handle pinned-message change events.

Copy

Pin an important message to the top of a conversation or unpin a previously pinned message. Pinned status is a shared conversation attribute. In group chats, pinning is typically restricted to group owners and administrators. Once pinned, member devices display the message prominently in a pinned banner at the top of the chat screen.

Code example

String conversationID = "g_group_123";
String clientMsgID = "msg_001";
boolean isPinned = true; // true: pin the message; false: unpin the message

OpenIMClient.getInstance().messageManager.setConversationPinnedMsg(
    new OnBase<String>() {
        @Override
        public void onSuccess(String data) {
            // Pinned status updated successfully
        }

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

Parameters

ParameterTypeRequiredDescription
baseOnBase<String>YesCallback handler for the asynchronous request.
conversationIDStringYesGlobally unique ID of the target conversation.
clientMsgIDStringYesClient message ID of the target message to pin or unpin.
isPinnedbooleanYesPin status flag: true to pin the message, false to unpin it.

Return value

Upon success, data in onSuccess returns a confirmation message.

State changes after the call

  1. Callback confirmation: The onSuccess callback indicates that the pinned state change was saved on the server.
  2. Asynchronous event delivery: Conversation members receive the change event through OnAdvanceMsgListener.onChangedPinnedMsg:
@Override
public void onChangedPinnedMsg(ChangedPinnedMsg event) {
    // event.getConversationID() identifies the target conversation
    // event.getMsgs() returns the updated list of pinned messages
}

Clients should merge the new list of pinned items using event.getConversationID() and clientMsgID.

  1. Re-query calibration: To retrieve the complete current list of pinned messages directly from storage, see View pinned messages.

For complete listener registration and lifecycle management, see Receive messages.