Browse SDKs · Android
Platform
SDKsAndroid

Get the total unread count

Retrieve the total unread message count across all conversations for the authenticated user.

Copy

Retrieve the aggregate unread message count across all conversations for the authenticated account. This is typically used after login, upon application initialization, or when returning to the foreground to reconcile bottom navigation tab badges.

Code example

OpenIMClient.getInstance().conversationManager.getTotalUnreadMsgCount(
    new OnBase<String>() {
        @Override
        public void onSuccess(String value) {
            int totalUnread = Integer.parseInt(value);
            // totalUnread represents the total unread count.
        }

        @Override
        public void onError(int code, String error) {
            // code and error describe the failure.
        }
    }
);

Parameters

ParameterTypeRequiredDescription
baseOnBase<String>YesCallback delivering the asynchronous operation result.

Return value

The successful callback returns a String representing the total unread count. Parse it into an integer to update global badge counts across your application.

State changes after the call

Whenever new messages arrive, conversations are marked as read, or unread states synchronize from another client, the SDK dispatches updates via OnConversationListener.onTotalUnreadMessageCountChanged. For complete listener configuration, see Get the conversation list.