Browse SDKs · Android
SDKsAndroid

Relationship overview

Learn about friends, friend requests, and blacklist APIs in the Android SDK.

Copy

Relationships record friendships, friend requests, and blacklist entries between the current user and other users. Profiles, account settings, and online status belong to user capabilities. See User overview.

Relationship objects

Android SDK returns different objects for relationship scenarios:

TypeUse caseMain APIs
UserInfoUser profile and relationship data in friend lists, specified-friend queries, and the blacklistgetFriendListPage(), getFriendsInfo(), getBlacklist()
FriendInfoFriend profiles, remarks, and relationship extension dataUserInfo.getFriendInfo(), searchFriends()
FriendshipInfoFriendship result between the current user and a target usercheckFriend()
FriendApplicationInfoReceived and sent friend requests and their handling statusgetRecvFriendApplicationList(), getSendFriendApplicationList()
BlacklistInfoBlacklist relationship dataUserInfo.getBlackInfo(), getBlacklist()

UserInfo can contain friend or blacklist relationship data. Call getFriendInfo() to obtain FriendInfo, or getBlackInfo() to obtain BlacklistInfo.

Feature entry points

RequirementRecommended page
Page through, search, or retrieve specified friend profilesGet the friend list by page, Search friends, Get specified friend profiles
Check the friendship between the current user and a target userCheck friendship
Update or delete a friend relationshipUpdate friend profiles, Delete a friend
Send, retrieve, accept, or reject friend requestsSend a friend request, Get received friend requests, Get sent friend requests, Accept a friend request, Reject a friend request
View or maintain the blacklistGet the blacklist, Block a user, Unblock a user

State updates

Set the friendship listener for relationship state changes. See the corresponding capability pages below for details about each callback:

OpenIMClient client = OpenIMClient.getInstance();

client.friendshipManager.setOnFriendshipListener(new OnFriendshipListener() {
    @Override
    public void onFriendApplicationAdded(FriendApplicationInfo application) {
        // Handle friend request changes.
    }

    @Override
    public void onFriendApplicationAccepted(FriendApplicationInfo application) {
        // Handle an accepted friend request.
    }

    @Override
    public void onFriendApplicationRejected(FriendApplicationInfo application) {
        // Handle a rejected friend request.
    }

    @Override
    public void onFriendApplicationDeleted(FriendApplicationInfo application) {
        // Handle friend request deletion.
    }

    @Override
    public void onFriendAdded(FriendInfo friend) {
        // Handle friendship changes.
    }

    @Override
    public void onFriendInfoChanged(FriendInfo friend) {
        // Handle friend profile changes.
    }

    @Override
    public void onFriendDeleted(FriendInfo friend) {
        // Handle friendship deletion.
    }

    @Override
    public void onBlacklistAdded(BlacklistInfo user) {
        // Handle a new blacklist entry.
    }

    @Override
    public void onBlacklistDeleted(BlacklistInfo user) {
        // Handle blacklist entry deletion.
    }
});