Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Get friend count

Retrieve the total number of friend relationships established by the current account.

Copy

Query the aggregate friend relationship count without supplying parameters. This count is useful for contact statistics or determining whether to continue paging:

Code example

import sdk, { GetFriendListCountResp } from '@openimsdk/imsdk';

const response: GetFriendListCountResp = await sdk.getFriendListCount();
showFriendCount(response.count);

Return value

Returns a Promise that resolves to a GetFriendListCountResp object:

PropertyTypeDescription
countnumberThe total count of active friends in the local SDK database.

State changes after the call

The returned count reflects a point-in-time total and does not emit events. Maintain the count incrementally when friends are added or removed using the events documented in Paginate friend list, and re-query whenever calibration is required.