Subscribe to user status
Subscribe to the online presence and multi-platform login state of specified users.
Subscribe to real-time online status and multi-platform connection state for specified users. When subscription succeeds, the SDK delivers a snapshot of their current presence immediately and publishes incremental event updates whenever target users log in, disconnect, or change active platforms.
Code example
List<String> userIDs = Arrays.asList("user_a", "user_b");
OpenIMClient.getInstance().userInfoManager.subscribeUsersOnlineStatus(
new OnBase<List<UsersOnlineStatus>>() {
@Override
public void onSuccess(List<UsersOnlineStatus> states) {
// Render online presence indicators using states
}
@Override
public void onError(int code, String error) {
// Handle error
}
},
userIDs
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
base | OnBase<List<UsersOnlineStatus>> | Yes | Callback delivering the asynchronous operation result. |
userIDs | List<String> | Yes | List of target user IDs to subscribe to. Subscribe on demand when entering a chat or list view. |
Return value
The successful callback returns an initial presence snapshot as List<UsersOnlineStatus>. Maintain your presence cache using userID as the unique key:
| Field | Description |
|---|---|
userID | Target user ID. |
status | Presence status (1 for online, 0 for offline). |
platformIDs | List of active client platforms (such as Android, iOS, or Web platform codes). |
State changes after the call
Subsequent presence transitions for subscribed users arrive via OnUserListener:
@Override
public void onUserStatusChanged(UsersOnlineStatus status) {
// Received status update; update the UI matching status.getUserID()
}When navigating away from a chat screen or when presence tracking is no longer needed, call Unsubscribe from user status to conserve bandwidth and avoid unnecessary presence broadcasts.
Was this page helpful?