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) {
            // Use friends to update the friend list.
        }

        @Override
        public void onError(int code, String error) {
            // Handle the 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.

Friend profile fields

UserInfo.getFriendInfo() returns FriendInfo for a friend list item. Common fields are:

FieldDescription
userIDFriend user ID.
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.

Receive friend added, changed, and deleted callbacks through OnFriendshipListener:

@Override
public void onFriendAdded(FriendInfo friend) {
    // Handle the added friend.
}

@Override
public void onFriendInfoChanged(FriendInfo friend) {
    // Handle the changed friend.
}

@Override
public void onFriendDeleted(FriendInfo friend) {
    // Handle the deleted friend.
}