Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

// Message Listener - receive messages in real-time
CometChat.addMessageListener("message_listener", MessageListener(
  onTextMessageReceived: (TextMessage message) {
    debugPrint("Text received: ${message.text}");
  },
  onMediaMessageReceived: (MediaMessage message) {
    debugPrint("Media received: ${message.attachment?.fileUrl}");
  },
));

// User Listener - track user online/offline status
CometChat.addUserListener("user_listener", UserListener(
  onUserOnline: (User user) {
    debugPrint("${user.name} is online");
  },
  onUserOffline: (User user) {
    debugPrint("${user.name} is offline");
  },
));

// Group Listener - track group membership changes
CometChat.addGroupListener("group_listener", GroupListener(
  onGroupMemberJoined: (action, joinedUser, joinedGroup) {
    debugPrint("${joinedUser.name} joined ${joinedGroup.name}");
  },
  onGroupMemberLeft: (action, leftUser, leftGroup) {
    debugPrint("${leftUser.name} left ${leftGroup.name}");
  },
));

// Call Listener - track incoming/outgoing calls
CometChat.addCallListener("call_listener", CallListener(
  onIncomingCallReceived: (Call call) {
    debugPrint("Incoming call from: ${call.sender?.name}");
  },
  onOutgoingCallAccepted: (Call call) {
    debugPrint("Call accepted");
  },
));

// Connection Listener - monitor WebSocket connection
CometChat.addConnectionListener("conn_listener", ConnectionListener(
  onConnected: () => debugPrint("Connected"),
  onDisconnected: () => debugPrint("Disconnected"),
));

// Remove listeners when no longer needed
CometChat.removeMessageListener("message_listener");
CometChat.removeUserListener("user_listener");
CometChat.removeGroupListener("group_listener");
CometChat.removeCallListener("call_listener");
CometChat.removeConnectionListener("conn_listener");
CometChat provides real-time event listeners to keep your app updated with live changes. These listeners notify your app when messages are received, users come online/offline, group membership changes occur, calls are initiated, and connection state changes.
Listener Cleanup Required: Always remove listeners when they’re no longer needed (e.g., on widget dispose or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.
CometChat provides 7 listener types:
  1. MessageListener
  2. UserListener
  3. GroupListener
  4. CallListener
  5. ConnectionListener
  6. LoginListener
  7. AIAssistantListener

Message Listener

The MessageListener class provides you with live events related to messages. Below are the callback methods provided by the MessageListener class.

MessageListener Events

MethodParameter TypeDescription
onTextMessageReceived(TextMessage message)TextMessageTriggered when a text message is received
onMediaMessageReceived(MediaMessage message)MediaMessageTriggered when a media message is received
onCustomMessageReceived(CustomMessage message)CustomMessageTriggered when a custom message is received
onTypingStarted(TypingIndicator typingIndicator)TypingIndicatorTriggered when a user starts typing in a user/group conversation
onTypingEnded(TypingIndicator typingIndicator)TypingIndicatorTriggered when a user stops typing in a user/group conversation
onMessagesDelivered(MessageReceipt messageReceipt)MessageReceiptTriggered when messages are marked as delivered for a conversation
onMessagesRead(MessageReceipt messageReceipt)MessageReceiptTriggered when messages are marked as read for a conversation
onMessagesDeliveredToAll(MessageReceipt messageReceipt)MessageReceiptTriggered when messages are delivered to all participants
onMessagesReadByAll(MessageReceipt messageReceipt)MessageReceiptTriggered when messages are read by all participants
onMessageEdited(BaseMessage message)BaseMessageTriggered when a message is edited in a user/group conversation
onMessageDeleted(BaseMessage message)BaseMessageTriggered when a message is deleted in a user/group conversation
onMessageModerated(BaseMessage message)BaseMessageTriggered when a message is moderated
onTransientMessageReceived(TransientMessage message)TransientMessageTriggered when a transient message is received
onInteractiveMessageReceived(InteractiveMessage message)InteractiveMessageTriggered when an interactive message is received
onInteractionGoalCompleted(InteractionReceipt receipt)InteractionReceiptTriggered when an interaction goal is achieved
onMessageReactionAdded(ReactionEvent reactionEvent)ReactionEventTriggered when a reaction is added to a message
onMessageReactionRemoved(ReactionEvent reactionEvent)ReactionEventTriggered when a reaction is removed from a message
onAIAssistantMessageReceived(AIAssistantMessage message)AIAssistantMessageTriggered when an AI assistant message is received
onAIToolResultReceived(AIToolResultMessage message)AIToolResultMessageTriggered when an AI tool result message is received
onAIToolArgumentsReceived(AIToolArgumentMessage message)AIToolArgumentMessageTriggered when AI tool arguments are received
To add the MessageListener, you need to use the addMessageListener() method provided by the CometChat class.
ParameterTypeDescription
listenerIdStringA unique identifier for the listener. No two listeners should share the same ID.
listenerMessageListenerAn instance of a class that implements the MessageListener mixin
class Class_Name with MessageListener {

  //CometChat.addMessageListener("listenerId", this);
	@override
  void onTextMessageReceived(TextMessage textMessage) {

  }

  @override
  void onMediaMessageReceived(MediaMessage mediaMessage) {

  }

  @override
  void onCustomMessageReceived(CustomMessage customMessage) {

  }

    @override
  void onTypingStarted(TypingIndicator typingIndicator) {

  }

  @override
  void onTypingEnded(TypingIndicator typingIndicator) {

  }


  @override
  void onMessagesDelivered(MessageReceipt messageReceipt) {

  }

  @override
  void onMessagesRead(MessageReceipt messageReceipt) {

  }

  @override
  void onMessageEdited(BaseMessage message) {

  }

  @override
  void onMessageDeleted(BaseMessage message) {

  }

  @override
  void onInteractionGoalCompleted(InteractionReceipt receipt) {


  }

  @override
  void onInteractiveMessageReceived(InteractiveMessage message) {

  }


  @Override
  public void onTransientMessageReceived(TransientMessage transientMessage) {

  }

  @Override
  public void onMessageReactionAdded(ReactionEvent reactionEvent) {

  }

  @Override
  public void onMessageReactionRemoved(ReactionEvent reactionEvent) {

  }

}
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the activity/fragment where the MessageListener is declared is not in use, you need to remove the listener using the removeMessageListener() method which takes the id of the listener to be removed as the parameter. We suggest you call this method in the onPause() method of the activity/fragment.
CometChat.removeMessageListener(UNIQUE_LISTENER_ID)

User Listener

The UserListener class provides you with live events related to users. Below are the callback methods provided by the UserListener class.

UserListener Events

MethodParameter TypeDescription
onUserOnline(User user)UserTriggered when a user comes online and is available to chat. The details of the user can be obtained from the User object received as the method parameter.
onUserOffline(User user)UserTriggered when a user goes offline. The details of the user can be obtained from the User object received as the parameter.
To add the UserListener, you need to use the addUserListener() method provided by the CometChat class.
ParameterTypeDescription
listenerIdStringA unique identifier for the listener. No two listeners should share the same ID.
listenerUserListenerAn instance of a class that implements the UserListener mixin
class Class_Name with UserListener {
  //CometChat.addUserListener("user_Listener_id", this);
	@override
  void onUserOnline(User user) {

  }

  @override
  void onUserOffline(User user) {

  }

}
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the activity/fragment where the UserListener is declared is not in use, you need to remove the listener using the removeUserListener() method which takes the id of the listener to be removed as the parameter. We suggest you call this method in the onPause() method of the activity/fragment.
CometChat.removeUserListener(UNIQUE_LISTENER_ID)

Group Listener

The GroupListener class provides you with all the real-time events related to groups. Below are the callback methods provided by the GroupListener class.

GroupListener Events

MethodParameter TypesDescription
onGroupMemberJoined(Action action, User joinedUser, Group joinedGroup)Action, User, GroupTriggered when a user joins any group. All the members present in the group will receive this event.
onGroupMemberLeft(Action action, User leftUser, Group leftGroup)Action, User, GroupTriggered when a user who was a member of any group leaves the group. All the members of the group receive this event.
onGroupMemberKicked(Action action, User kickedUser, User kickedBy, Group kickedFrom)Action, User, User, GroupTriggered when a user is kicked from a group. All the members including the user receive this event.
onGroupMemberBanned(Action action, User bannedUser, User bannedBy, Group bannedFrom)Action, User, User, GroupTriggered when a user is banned from a group. All the members including the user receive this event.
onGroupMemberUnbanned(Action action, User unbannedUser, User unbannedBy, Group unbannedFrom)Action, User, User, GroupTriggered when a user is unbanned from a group. All the members of the group receive this event.
onGroupMemberScopeChanged(Action action, User updatedBy, User updatedUser, String scopeChangedTo, String scopeChangedFrom, Group group)Action, User, User, String, String, GroupTriggered when the scope of any group member has been changed. All the members that are a part of that group receive this event.
onMemberAddedToGroup(Action action, User addedBy, User userAdded, Group addedTo)Action, User, User, GroupTriggered when a user is added to any group. All the members including the user himself receive this event.
To add the GroupListener, you need to use the addGroupListener() method provided by the CometChat class.
ParameterTypeDescription
listenerIdStringA unique identifier for the listener. No two listeners should share the same ID.
listenerGroupListenerAn instance of a class that implements the GroupListener mixin
class Class_Name with GroupListener {
  //CometChat.addGroupListener("UNIQUE_LISTENER_ID", this);

  @override
  void onGroupMemberJoined(Action action, User joinedUser, Group joinedGroup) {

  }

  @override
  void onGroupMemberLeft(Action action, User leftUser, Group leftGroup) {

  }

  @override
  void onGroupMemberKicked(Action action, User kickedUser, User kickedBy, Group kickedFrom) {

  }

  @override
  void onGroupMemberBanned(Action action, User bannedUser, User bannedBy, Group bannedFrom) {

  }

  @override
  void onGroupMemberUnbanned(Action action, User unbannedUser, User unbannedBy, Group unbannedFrom) {

  }

  @override
  void onGroupMemberScopeChanged(Action action, User updatedBy, User updatedUser, String scopeChangedTo, String scopeChangedFrom, Group group) {

  }

  @override
  void onMemberAddedToGroup(Action action, User addedby, User userAdded, Group addedTo) {

  }

}
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the activity/fragment where the GroupListener is declared is not in use, you need to remove the listener using the removeGroupListener() method which takes the id of the listener to be removed as the parameter. We suggest you call this method in the onPause() method of the activity/fragment.
CometChat.removeGroupListener(UNIQUE_LISTENER_ID)

Call Listener

The CallListener class provides you with real-time events related to calls. Below are the callback methods provided by the CallListener class.

CallListener Events

MethodParameter TypeDescription
onIncomingCallReceived(Call call)CallTriggered when an incoming call is received
onOutgoingCallAccepted(Call call)CallTriggered when an outgoing call is accepted by the receiver
onOutgoingCallRejected(Call call)CallTriggered when an outgoing call is rejected by the receiver
onIncomingCallCancelled(Call call)CallTriggered when an incoming call is cancelled by the caller
onCallEndedMessageReceived(Call call)CallTriggered when a call ended message is received
To add the CallListener, you need to use the addCallListener() method provided by the CometChat class.
ParameterTypeDescription
listenerIdStringA unique identifier for the listener. No two listeners should share the same ID.
listenerCallListenerAn instance of a class that implements the CallListener mixin
class Class_Name with CallListener {
  //CometChat.addCallListener("UNIQUE_LISTENER_ID", this);

  @override
  void onIncomingCallReceived(Call call) {

  }

  @override
  void onOutgoingCallAccepted(Call call) {

  }

  @override
  void onOutgoingCallRejected(Call call) {

  }

  @override
  void onIncomingCallCancelled(Call call) {

  }

  @override
  void onCallEndedMessageReceived(Call call) {

  }

}
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the CallListener is no longer needed, remove it using the removeCallListener() method.
CometChat.removeCallListener(UNIQUE_LISTENER_ID)

Connection Listener

The ConnectionListener class provides you with real-time events related to the WebSocket connection status. Below are the callback methods provided by the ConnectionListener class.

ConnectionListener Events

MethodParameter TypeDescription
onConnected()Triggered when the SDK successfully establishes a connection to the WebSocket server
onConnecting()Triggered when the SDK is attempting to establish a connection to the WebSocket server
onDisconnected()Triggered when the SDK gets disconnected due to network fluctuations or other issues
onFeatureThrottled()Triggered when CometChat automatically toggles off certain features to prevent performance loss
onConnectionError(CometChatException error)CometChatExceptionTriggered when an error occurs while maintaining the WebSocket connection
To add the ConnectionListener, you need to use the addConnectionListener() method provided by the CometChat class.
ParameterTypeDescription
listenerIdStringA unique identifier for the listener. No two listeners should share the same ID.
listenerConnectionListenerAn instance of a class that implements the ConnectionListener mixin
class Class_Name with ConnectionListener {
  //CometChat.addConnectionListener("UNIQUE_LISTENER_ID", this);

  @override
  void onConnected() {

  }

  @override
  void onConnecting() {

  }

  @override
  void onDisconnected() {

  }

  @override
  void onFeatureThrottled() {

  }

  @override
  void onConnectionError(CometChatException error) {

  }

}
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the ConnectionListener is no longer needed, remove it using the removeConnectionListener() method.
CometChat.removeConnectionListener(UNIQUE_LISTENER_ID)

Login Listener

The LoginListener class provides you with real-time events related to user authentication. Below are the callback methods provided by the LoginListener class.

LoginListener Events

MethodParameter TypeDescription
loginSuccess(User user)UserTriggered when a user successfully logs in
loginFailure(CometChatException e)CometChatExceptionTriggered when a login attempt fails
logoutSuccess()Triggered when a user successfully logs out
logoutFailure(CometChatException e)CometChatExceptionTriggered when a logout attempt fails
To add the LoginListener, you need to use the addLoginListener() method provided by the CometChat class.
ParameterTypeDescription
listenerIdStringA unique identifier for the listener. No two listeners should share the same ID.
listenerLoginListenerAn instance of a class that implements the LoginListener mixin
class Class_Name with LoginListener {
  //CometChat.addLoginListener("UNIQUE_LISTENER_ID", this);

  @override
  void loginSuccess(User user) {

  }

  @override
  void loginFailure(CometChatException e) {

  }

  @override
  void logoutSuccess() {

  }

  @override
  void logoutFailure(CometChatException e) {

  }

}
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the LoginListener is no longer needed, remove it using the removeLoginListener() method.
CometChat.removeLoginListener(UNIQUE_LISTENER_ID)

AI Assistant Listener

The AIAssistantListener class provides you with real-time events related to AI assistant interactions. Below are the callback methods provided by the AIAssistantListener class.

AIAssistantListener Events

MethodParameter TypeDescription
onAIAssistantEventReceived(AIAssistantBaseEvent aiAssistantBaseEvent)AIAssistantBaseEventTriggered when an AI assistant event is received
To add the AIAssistantListener, you need to use the addAIAssistantListener() method provided by the CometChat class.
ParameterTypeDescription
listenerIdStringA unique identifier for the listener. No two listeners should share the same ID.
listenerAIAssistantListenerAn instance of a class that implements the AIAssistantListener mixin
class Class_Name with AIAssistantListener {
  //CometChat.addAIAssistantListener("UNIQUE_LISTENER_ID", this);

  @override
  void onAIAssistantEventReceived(AIAssistantBaseEvent aiAssistantBaseEvent) {

  }

}
where UNIQUE_LISTENER_ID is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events. Once the AIAssistantListener is no longer needed, remove it using the removeAIAssistantListener() method.
CometChat.removeAIAssistantListener(UNIQUE_LISTENER_ID)

Next Steps

Receive Messages

Handle incoming messages in real-time using message listeners

User Presence

Track when users come online or go offline

Typing Indicators

Show real-time typing status in conversations

Delivery & Read Receipts

Track message delivery and read status

Connection Status

Monitor SDK connection to CometChat servers

Login Listeners

Monitor user login and logout events