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.

// Kick a member (can rejoin)
CometChat.kickGroupMember("UID", "GUID", object : CallbackListener<String>() {
    override fun onSuccess(message: String) { }
    override fun onError(e: CometChatException) { }
})

// Ban a member (cannot rejoin without unban)
CometChat.banGroupMember("UID", "GUID", callback)

// Unban a member
CometChat.unbanGroupMember("UID", "GUID", callback)
Note: Only admins and moderators can kick, ban, or unban members.
Admins and moderators can kick, ban, or unban group members. Kicked users can rejoin; banned users cannot until unbanned.

Kick a Group Member

The Admin or Moderator of a group can kick a member out of the group using the kickGroupMember() method.
private String UID = "UID";
private String GUID = "GUID";

CometChat.kickGroupMember(UID, GUID, new CometChat.CallbackListener<String>() {
  @Override
  public void onSuccess(String successMessage) {
    Log.d(TAG, "Group member kicked successfully");
  }
  @Override
  public void onError(CometChatException e) {
    Log.d(TAG, "Group member kicking failed with exception: " + e.getMessage());
  }
});
The kickGroupMember() takes following parameters:
ParameterDescription
UIDThe UID of the user to be kicked
GUIDThe GUID of the group from which user is to be kicked
The kicked user will be no longer part of the group and can not perform any actions in the group, but the kicked user can rejoin the group.

Ban a Group Member

The Admin or Moderator of the group can ban a member from the group using the banGroupMember() method.
private String UID = "UID";
private String GUID = "GUID";

CometChat.banGroupMember(UID, GUID, new CometChat.CallbackListener<String>() {
  @Override
  public void onSuccess(String successMessage) {
    Log.d(TAG, "Group member banned successfully");
  }
  @Override
  public void onError(CometChatException e) {
    Log.d(TAG, "Group member banning failed with exception: " + e.getMessage());
  }
});
The banGroupMember() method takes the following parameters:
ParameterDescription
UIDThe UID of the user to be banned
GUIDThe GUID of the group from which user is to be banned
The banned user will be no longer part of the group and can not perform any actions in the group. A banned user cannot rejoin the group same group without being unbanned.

Unban a Banned Group Member from a Group

Only Admin or Moderators of the group can unban a previously banned member from the group using the unbanGroupMember() method.
private String UID = "UID";
private String GUID = "GUID";

CometChat.unbanGroupMember(UID, GUID, new CometChat.CallbackListener<String>() {
  @Override
  public void onSuccess(String successMessage) {
    Log.d(TAG, "Group Member unbanned successfully");
  }
  @Override
  public void onError(CometChatException e) {
    Log.d(TAG, "Group Member unbanning failed with exception: " + e.getMessage());
  }
});
The unbanGroupMember() method takes the following parameters
ParameterDescription
UIDThe UID of the user to be unbanned
GUIDThe UID of the group from which user is to be banned
The unbanned user can now rejoin the group.

Get List of Banned Members for a Group

Use BannedGroupMembersRequestBuilder with the group GUID to fetch banned members.

Set Limit

Set the number of banned members to fetch per request.
BannedGroupMembersRequest bannedGroupMembersRequest = new BannedGroupMembersRequest.BannedGroupMembersRequestBuilder(GUID)
  .setLimit(limit)
  .build();

Set Search Keyword

Filter banned members by a search string.
BannedGroupMembersRequest bannedGroupMembersRequest = new BannedGroupMembersRequest.BannedGroupMembersRequestBuilder(GUID)
  .setSearchKeyword("abc")
  .build();

Fetch Banned Members

After configuring the builder, call build() then fetchNext() to retrieve banned members.
private BannedGroupMembersRequest bannedGroupMembersRequest = null;
private String GUID = "GUID";
private int limit = 30;

bannedGroupMembersRequest = new BannedGroupMembersRequest.BannedGroupMembersRequestBuilder(GUID).setLimit(limit).build();

bannedGroupMembersRequest.fetchNext(new CometChat.CallbackListener<List<GroupMember>>(){
  @Override
  public void onSuccess(List <GroupMember> list) {
    Log.d(TAG, "Banned Group Member list fetched successfully: " + list.size());
  }
  @Override
  public void onError(CometChatException e) {
    Log.d(TAG, "Banned Group Member list fetching failed with exception: " + e.getMessage());
  }
});

Real-Time Group Member Kicked/Banned Events

When a member is kicked, banned, or unbanned, group members receive real-time events via the GroupListener class. The callbacks provide an Action object, the affected User, the acting User, and the Group.
CometChat.addGroupListener(GroupChatActivity.class.getSimpleName(), new CometChat.GroupListener() {
  @Override
  public void onGroupMemberKicked(Action action, User kickedUser, User kickedBy, Group kickedFrom) {

  }

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

  }

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

  }
});

Missed Group Member Kicked/Banned Events

When fetching message history, kick/ban/unban actions appear as Action messages with these fields:
  1. action - kicked
  2. actionBy - User object containing the details of the user who has kicked the member
  3. actionOn - User object containing the details of the member that has been kicked
  4. actionFor - Group object containing the details of the Group from which the member was kicked
For group member banned event, the details can be obtained using the below fields of the Action class-
  1. action - banned
  2. actionBy - User object containing the details of the user who has banned the member
  3. actionOn - User object containing the details of the member that has been banned
  4. actionFor - Group object containing the details of the Group from which the member was banned
For group member unbanned event, the details can be obtained using the below fields of the Action class-
  1. action - unbanned
  2. actionBy - User object containing the details of the user who has unbanned the member
  3. actionOn - User object containing the details of the member that has been unbanned
  4. actionFor - Group object containing the details of the Group from which the member was unbanned
Always remove group listeners when they’re no longer needed (e.g., in onDestroy() or when navigating away). Failing to remove listeners can cause memory leaks and duplicate event handling.

Next Steps

Add Members

Add new members to groups

Change Member Scope

Update member roles and permissions

Retrieve Members

Fetch list of group members

Group Listeners

Handle real-time group events