Browse SDKs · Android
Platform
SDKsAndroid

Check friendship status

Batch verify friendship relationships between specified users and the authenticated account using checkFriend().

Copy

Batch verify whether specified users have active friendship relationships with the authenticated account. This is typically used on user profile screens to toggle between "Add friend" and "Send message" actions.

Code example

OpenIMClient.getInstance().friendshipManager.checkFriend(
    new OnBase<List<FriendshipInfo>>() {
        @Override
        public void onSuccess(List<FriendshipInfo> relations) {
            // Update relationship UI using relations
        }

        @Override
        public void onError(int code, String error) {
            // Handle error
        }
    },
    Arrays.asList("user_a", "user_b")
);

Parameters

ParameterTypeRequiredDescription
baseOnBase<List<FriendshipInfo>>YesCallback delivering the asynchronous operation result.
userIDsList<String>YesList of user IDs to check.

Return value

The successful callback returns a List<FriendshipInfo>. Match records using userID as the primary key:

FieldDescription
userIDTarget user ID.
resultFriendship status code: 1 indicates the user is an active friend and not blocked; 0 indicates no friendship exists.

To retrieve detailed profiles including nicknames, avatars, and remarks, see Get friend profiles.