Browse SDKs · Android
SDKsAndroid

Search messages

Use searchLocalMessages to search messages synchronized to the current account’s local storage.

Copy

searchLocalMessages() searches messages already synchronized to the current account on this device. It does not query a global application backend. Limit the search by conversation, keywords, senders, message types, and time range. Pass null for conversationID to search all local conversations.

Parameters

ParameterTypeRequiredDescription
conversationIDStringNoConversation restriction; pass null for all local conversations.
keywordListList<String>YesNon-empty search terms.
keywordListMatchTypeintYesSDK match mode for requiring all terms or any term.
senderUserIDListList<String>NoSender filter; pass an empty list for no restriction.
messageTypeListList<Integer>NoMessage-type filter; pass an empty list for no restriction.
searchTimePositionintYesTime anchor; 0 means no anchor restriction.
searchTimePeriodintYesSeconds searched backward from the anchor; 0 means no time restriction.
pageIndexintYesPage index, starting at 0.
countintYesMaximum results per page.
OpenIMClient.getInstance().messageManager.searchLocalMessages(
    new OnBase<SearchResult>() {
        @Override
        public void onSuccess(SearchResult result) {
            // result.getSearchResultItems() groups matching messages by conversation.
        }

        @Override
        public void onError(int code, String error) {
            // Keep previous results and report the failure.
        }
    },
    conversationID,
    keywords,
    1,
    senderIDs,
    messageTypes,
    0,
    0,
    0,
    20
);

Result

The success callback returns SearchResult. totalCount is the number of matched messages. searchResultItems groups the conversation ID, display name, avatar, match count, and message list for each conversation. Search results belong to the current search UI and do not replace a conversation's complete message list or trigger message events.