Skip to main content
// Subscribe to presence during init
val appSettings = AppSettings.AppSettingsBuilder()
    .subscribePresenceForAllUsers()
    .setRegion("REGION")
    .build()
CometChat.init(context, "APP_ID", appSettings, callback)

// Add user listener
CometChat.addUserListener("LISTENER_ID", object : CometChat.UserListener() {
    override fun onUserOnline(user: User?) {
        Log.d(TAG, "${user?.name} is online")
    }
    override fun onUserOffline(user: User?) {
        Log.d(TAG, "${user?.name} is offline")
    }
})

// Remove listener (important!)
CometChat.removeUserListener("LISTENER_ID")
User Presence lets you know if a user is available to chat. Configure presence subscription during init(), then listen for online/offline events via UserListener.

Real-time Presence

Based on the AppSettings configured during init(), the logged-in user receives presence updates for other users. AppSettingsBuilder provides three subscription options:
  • subscribePresenceForAllUsers() — Receive presence for all users in the app.
  • subscribePresenceForRoles(List<String> roles) — Receive presence only for users with specified roles.
  • subscribePresenceForFriends() — Receive presence only for friends.
If none are set, no presence events are sent. Register UserListener in onResume() and remove it in onPause().
private String listenerID = "UNIQUE_LISTENER_ID";

CometChat.addUserListener(listenerID, new CometChat.UserListener() {
  @Override public void onUserOnline(User user) {
    Log.d(TAG, user.getName() + "is online.");
  }
  @Override public void onUserOffline(User user) {
    Log.d(TAG, user.getName() + "is offline.");
  }
});   
ParameterDescription
listenerIDAn ID that uniquely identifies that listener. We recommend using the activity or fragment name.
Remove the listener in onPause() when the activity or fragment is no longer in use.
private String listenerID = "UNIQUE_LISTENER_ID";

CometChat.removeUserListener(listenerID);     
Always remove listeners when they’re no longer needed (e.g., in onPause() or onDestroy()). Failing to remove listeners can cause memory leaks and duplicate event handling.

User List Presence

When you retrieve the list of users, each User object includes:
  • status"online" or "offline"
  • lastActiveAt — Unix timestamp of when the user was last online (useful for “Last seen” indicators)


Next Steps

Retrieve Users

Fetch user lists with presence information

Connection Status

Monitor SDK connection state and handle reconnection

User Management

Learn about user objects and properties

Real-Time Listeners

Understand all available event listeners