Browse SDKs · Android
SDKsAndroid

Get received friend requests

Use getRecvFriendApplicationList() to query received friend requests by page.

Copy
GetFriendApplicationListAsRecipientReq request =
    new GetFriendApplicationListAsRecipientReq(0, 20);

OpenIMClient.getInstance().friendshipManager.getRecvFriendApplicationList(
    new OnBase<List<FriendApplicationInfo>>() {
        @Override
        public void onSuccess(List<FriendApplicationInfo> applications) {
            replaceReceivedApplications(applications);
        }

        @Override
        public void onError(int code, String error) {
            recordReceivedApplicationFailure(code, error);
        }
    },
    request
);

offset starts at 0, and count is the page size. To filter by handling state, use setHandleResults(int[]) with values defined by the server contract. The callback returns the current page as List<FriendApplicationInfo>.

FieldDescription
fromUserID / fromNickname / fromFaceURLApplicant ID, nickname, and avatar snapshot.
toUserID / toNickname / toFaceURLRecipient ID, nickname, and avatar snapshot.
reqMsgFriend request message.
handleResultHandling result: 0 pending, 1 accepted, 2 rejected.
handlerUserIDUser ID that handled the request; it can be empty while pending.
handleMsgHandling message.
handleTimeHandling time; do not treat it as valid while pending.
createTimeRequest creation time.
exFriend request extension string.

Use fromUserID:toUserID as the stable request key. This page owns the friend request added, accepted, rejected, and deleted callbacks. Combine them into the application's single OnFriendshipListener:

@Override
public void onFriendApplicationAdded(FriendApplicationInfo application) {
    friendApplicationStore.merge(application);
}

@Override
public void onFriendApplicationAccepted(FriendApplicationInfo application) {
    friendApplicationStore.merge(application);
}

@Override
public void onFriendApplicationRejected(FriendApplicationInfo application) {
    friendApplicationStore.merge(application);
}

@Override
public void onFriendApplicationDeleted(FriendApplicationInfo application) {
    friendApplicationStore.remove(
        application.getFromUserID(),
        application.getToUserID()
    );
}

Use whether toUserID equals the signed-in user ID to route a record to the received or sent list. After an application is accepted, onFriendAdded, owned by Get the friend list by page, merges the new friendship.