Browse SDKs · Android
SDKsAndroid

Get the friend list by page

Use getFriendListPage() to retrieve the current user friend list by page.

Copy
OpenIMClient.getInstance().friendshipManager.getFriendListPage(
    new OnBase<List<UserInfo>>() {
        @Override
        public void onSuccess(List<UserInfo> friends) {
            for (UserInfo friend : friends) {
                friendStore.put(friend.getUserID(), friend);
            }
        }

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

The arguments after the callback are offset, count, and filterBlack. offset starts at 0, count is the page size, and filterBlack removes blocked users when true. The callback returns the current page as List<UserInfo>; call getFriendInfo() on each item for relationship details. Increase offset by the requested item count when loading another page; a page smaller than count normally marks the end.

Use the paged API instead of getFriendList(). Merge snapshots and increments by userID.

Friend profile fields

UserInfo is the Android wrapper object. getFriendInfo() returns FriendInfo for a friend list item. Common fields are:

FieldDescription
userIDFriend user ID and the stable friend-list key.
nicknameAccount nickname of the friend.
faceURLAccount avatar URL of the friend.
remarkFriend remark set by the current account.
exFriendship extension string.
addSourceSource that created the friendship.
operatorUserIDUser ID that created or updated the relationship.
createTimeFriendship creation time.

nickname and faceURL are account data, while remark and ex belong to the friendship. UpdateFriendsReq can submit isPinned, but the current Android FriendInfo model has no corresponding read field, so pinned state needs application-owned storage. Do not use a friend object to overwrite a stranger's PublicUserInfo, or write a friend remark back to the account nickname.

This page owns the friend added, changed, and deleted callbacks. Combine them into the application's single OnFriendshipListener:

@Override
public void onFriendAdded(FriendInfo friend) {
    friendStore.put(friend.getUserID(), friend);
}

@Override
public void onFriendInfoChanged(FriendInfo friend) {
    friendStore.put(friend.getUserID(), friend);
}

@Override
public void onFriendDeleted(FriendInfo friend) {
    friendStore.remove(friend.getUserID());
}