Browse SDKs · Android
SDKsAndroidEnterprise

Load message context

Retrieve messages before and after a specified message with the Android SDK.

Copy

When navigating from a search result or referenced message into its chat context, use the Message already retrieved as the anchor.

Parameters

ParameterTypeRequiredDescription
conversationIDStringYesID of the conversation containing the anchor message.
startMsgMessageYesPreviously retrieved anchor message.
typeViewTypeYesContext type. Use ViewType.History for a referenced message and ViewType.Search for a search result.
beforeintYesMaximum number of messages to retrieve before the anchor.
afterintYesMaximum number of messages to retrieve after the anchor.
messageManager.fetchSurroundingMessages(
    new OnBase<Messages>() {
        @Override
        public void onSuccess(Messages messages) {
            List<Message> surrounding = messages.getData();
            // surrounding contains the target message and its context.
        }

        @Override
        public void onError(int code, String error) {
            // Handle the failure
        }
    },
    conversationID,
    targetMessage,
    ViewType.Search,
    20,
    20
);

In the success callback, messages.getData() is the list retrieved before and after the anchor. For message fields, see Message overview.

before and after independently limit the number of messages on either side. The result can contain fewer messages than requested when the anchor is near a history boundary or some messages have been deleted. If the message must first be located, see Find messages by ID.