Browse SDKs · Android
Platform
SDKsAndroid

Search friends

Search friends locally by keywords matching user ID, nickname, and remark alias.

Copy

Perform local fuzzy searches across the authenticated account's friend database, matching by user ID, nickname, and remark name.

Code example

OpenIMClient.getInstance().friendshipManager.searchFriends(
    new OnBase<List<FriendInfo>>() {
        @Override
        public void onSuccess(List<FriendInfo> results) {
            // Display search results using results
        }

        @Override
        public void onError(int code, String error) {
            // Handle error
        }
    },
    Collections.singletonList(keyword.trim()),
    true,
    true,
    true
);

Parameters

ParameterTypeRequiredDescription
baseOnBase<List<FriendInfo>>YesCallback delivering the asynchronous operation result.
keywordListList<String>YesList of search keywords, typically containing a single non-empty query string.
isSearchUserIDbooleanYesWhether to search against user IDs.
isSearchNicknamebooleanYesWhether to search against nicknames.
isSearchRemarkbooleanYesWhether to search against remark names.

At least one search toggle must be set to true.

Return value

The successful callback returns matching records as List<FriendInfo>. Deduplicate and render results using userID as the primary key. If no matching friends are found, an empty list is returned.