Enable seven core group-management features in your Android app using CometChat UIKit v5:
  • Create Group
  • Join Group
  • View Members
  • Add Member
  • Ban Member
  • Change Member Scope
  • Transfer Ownership
These moderation tools transform a static chat into a dynamic, manageable experience, all accessible via a clean UI.

Overview

A user can create or join a group, then open a dialog to:
  • View current members.
  • Add or ban participants.
  • Change member roles (e.g., member, moderator).
  • Delegate group ownership.
Typically, a FloatingActionButton (FAB) or menu item launches the group-management dialog, which uses CometChat Core SDK calls under the hood.

Prerequisites

  • Android Studio project with cometchat/cometchat-uikit-android and cometchat/chat-sdk-android in build.gradle.
  • Internet permission in AndroidManifest.xml.
  • Valid CometChat App ID, Region, and Auth Key configured via UIKitSettings.
  • User logged in with CometChatUIKit.login().
  • A MessagesActivity (or ConversationActivity) and an optional GroupDetailsActivity in your flow.

Components

Component / ClassRole
FloatingActionButtonTriggers the group-management options dialog.
GroupMembersRequestFetches current group members.
UsersRequestFetches all app users for the “Add Member” list.
CometChat.createGroup(...)Creates a new public or private group.
CometChat.joinGroup(...)Joins an existing group by GUID.
CometChat.addMembersToGroup(...)Adds selected users to the group.
CometChat.banGroupMember(...)Bans a member from the group.
CometChat.updateGroupMemberScope(...)Changes a member’s role (scope).
CometChat.transferGroupOwnership(...)Delegates group ownership to another member.

Integration Steps

1. Layout/UI Setup

Add a FAB to launch the group-management dialog.
<!-- activity_message.xml -->
<com.google.android.material.floatingactionbutton.FloatingActionButton
  android:id="@+id/fab_group_actions"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="end|bottom"
  android:src="@drawable/ic_group_actions" />
File reference:
activity_messages.xml

2. Wiring UI in Activity

Initialize UIKit views and respond to FAB clicks.
// In MessagesActivity.java
FloatingActionButton fab = findViewById(R.id.fab_group_actions);
fab.setOnClickListener(v -> showGroupActionsDialog());

private void showGroupActionsDialog() {
  // Present options: Create, Join, View Members, etc.
}
File reference:
MessagesActivity.java

3. Create & Join Group

Allow users to create or join a group via Core SDK.
// Create Group
CometChat.createGroup(new Group(
  groupGuid,
  groupName,
  CometChatConstants.GROUP_TYPE_PUBLIC,
  "" // password if needed
), new CometChat.CallbackListener<Group>() {
  // handle success/error
});

// Join Group
CometChat.joinGroup(
  groupGuid,
  CometChatConstants.GROUP_TYPE_PUBLIC,
  "",
  new CometChat.CallbackListener<Group>() {
    // handle success/error
  }
);
File reference:
GroupDetailsActivity.java

4. View Group Members

Fetch and display the current member list.
GroupMembersRequest membersRequest = new GroupMembersRequest.Builder(groupGuid).setLimit(50).build();
membersRequest.fetchNext(new CometChat.CallbackListener<List<GroupMember>>() {
  @Override
  public void onSuccess(List<GroupMember> members) {
    showMembersDialog(members);
  }
  @Override
  public void onError(CometChatException e) {}
});
File reference:
GroupDetailsActivity.java

5. Add Member

Select users not in the group and add them.
UsersRequest usersRequest = new UsersRequest.UsersRequestBuilder().setLimit(50).build();
usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {
  public void onSuccess(List<User> allUsers) {
    // filter out existing members, show selection dialog
  }
});
// On selection:
CometChat.addMembersToGroup(
  groupGuid,
  selectedUids,
  CometChatConstants.SCOPE_PARTICIPANT,
  new CometChat.CallbackListener<HashMap<String, String>>() {
    // handle result
  }
);
File reference:
GroupDetailsActivity.java

6. Ban Member, Change Scope & Transfer Ownership

Perform moderation actions on selected members.
// Ban Member
CometChat.banGroupMember(
  uid,
  groupGuid,
  new CometChat.CallbackListener<String>() { /*...*/ }
);

// Change Scope
CometChat.updateGroupMemberScope(
  uid,
  groupGuid,
  CometChatConstants.SCOPE_MODERATOR,
  new CometChat.CallbackListener<String>() { /*...*/ }
);

// Transfer Ownership
CometChat.transferGroupOwnership(
  uid,
  groupGuid,
  new CometChat.CallbackListener<String>() { /*...*/ }
);
File reference:
GroupDetailsActivity.java

Implementation Flow Summary

StepAction
1User taps FAB → showGroupActionsDialog()
2Select operation (e.g., View Members)
3Fetch data via GroupMembersRequest
4Call Core SDK method for chosen operation
5Show success or error feedback

Customization Options

  • Use a BottomSheetDialog instead of a standard dialog.
  • Implement multi-select for bulk actions (e.g., add multiple members).
  • Replace default dialogs with custom RecyclerView lists.
  • Control permissions: show options only to admins or owners.

Error Handling & Edge Cases

  • Not in Group: Disable join option if user is already member.
  • Permission Denied: Only show ban/transfer options to group admins.
  • Empty Lists: Display an empty-state view if no members or users.
  • Pagination: Implement fetchNext() in scroll listeners for large groups.

Feature Matrix

FeatureSDK MethodSelection Source
Create GroupCometChat.createGroup()Dialog input
Join GroupCometChat.joinGroup()Dialog input
View MembersGroupMembersRequest.fetchNext()Group members list
Add MemberCometChat.addMembersToGroup()App users list
Ban MemberCometChat.banGroupMember()Group members list
Change Member ScopeCometChat.updateGroupMemberScope()Group members list
Transfer OwnershipCometChat.transferGroupOwnership()Group members list

Android Sample App (Java)

Explore this feature in the CometChat SampleApp: GitHub → SampleApp

Android Sample App (Kotlin)

Explore this feature in the CometChat SampleApp: GitHub → SampleApp