Browse SDKs · Android
Platform
SDKsAndroid

Get the friend list

Paginate the friend list for the authenticated user and synchronize friendship events in real time.

Copy

Paginate the friend list for the authenticated account to prevent excessive memory and network overhead. Each record contains basic user profile information alongside friend-specific attributes like remarks and source details.

Code example

OpenIMClient.getInstance().friendshipManager.getFriendListPage(
    new OnBase<List<UserInfo>>() {
        @Override
        public void onSuccess(List<UserInfo> friends) {
            // Update friend list UI using friends
        }

        @Override
        public void onError(int code, String error) {
            // Handle error
        }
    },
    0,
    40,
    true
);

Parameters

ParameterTypeRequiredDescription
baseOnBase<List<UserInfo>>YesCallback delivering the asynchronous operation result.
offsetintYesZero-based paging offset; pass 0 for the initial page.
countintYesNumber of friend records to return in this page.
filterBlackbooleanYesWhen true, automatically filters out blocked users; when false, includes them.

Return value

The successful callback returns the current page as List<UserInfo>. Deduplicate and merge items into your local cache using userID as the unique key. When the returned item count is less than count, the end of the list has been reached.

Commonly used fields within the friend records include:

FieldDescription
userIDGlobal user ID of the friend.
nicknamePublic display nickname of the friend.
faceURLAvatar URL of the friend.
remarkPrivate remark alias set by the authenticated user.
exCustom relationship extension metadata.
addSourceChannel or source through which friendship was established.
operatorUserIDUser ID of the operator who initiated or approved the relationship.
createTimeUnix timestamp when friendship was established.

State changes after the call

When friends are added, modified, or removed, the SDK dispatches real-time events via OnFriendshipListener. Use userID as the primary key to merge updates or delete entries:

@Override
public void onFriendAdded(FriendInfo friend) {
    // New friend added; insert into the list or refresh UI
}

@Override
public void onFriendInfoChanged(FriendInfo friend) {
    // Nickname, remark, or avatar updated; refresh the item matching friend.getUserID()
}

@Override
public void onFriendDeleted(FriendInfo friend) {
    // Friendship terminated; remove the entry matching friend.getUserID() from local cache
}