> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Group

> Create public, private, and password-protected CometChat groups with the Android SDK and configure group details.

> [accordion] AI Integration Quick Reference
>
> ```kotlin theme={null}
> // Create a public group
> val group = Group("GUID", "Group Name", CometChatConstants.GROUP_TYPE_PUBLIC, "")
> CometChat.createGroup(group, object : CometChat.CallbackListener<Group>() {
>     override fun onSuccess(group: Group) { }
>     override fun onError(e: CometChatException) { }
> })
>
> // Create with members
> val groupMembers = listOf(
>     GroupMember("uid1", CometChatConstants.SCOPE_ADMIN),
>     GroupMember("uid2", CometChatConstants.SCOPE_PARTICIPANT)
> )
> CometChat.createGroupWithMembers(group, groupMembers, emptyList(), callback)
> ```

## Create a Group

Use `createGroup()` with a [`Group`](https://www.cometchat.com/docs/sdk/reference/entities#group) object. The `groupType` must be one of:

1. `CometChatConstants.GROUP_TYPE_PUBLIC`
2. `CometChatConstants.GROUP_TYPE_PASSWORD`
3. `CometChatConstants.GROUP_TYPE_PRIVATE`

> [tab] Java
>
> ```java theme={null}
> private String GUID = "GUID";
> private String groupName = "Hello Group!";
> private String groupType = CometChatConstants.GROUP_TYPE_PUBLIC;
> private String password = "";
>
> Group group = new Group(GUID, groupName, groupType, password);
>
> CometChat.createGroup(group, new CometChat.CallbackListener<Group>(){
> @Override
> public void onSuccess(Group group) {
>   Log.d(TAG, "Group created successfully: " + group.toString());
> }
> @Override
> public void onError(CometChatException e) {
>   Log.d(TAG, "Group creation failed with exception: " + e.getMessage());
> }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val GUID:String="GUID"
> val groupName:String="Hello Group"
> val groupType:String=CometChatConstants.GROUP_TYPE_PUBLIC
> val password:String=""
>
> val group=Group(GUID,groupName,groupType,password)
>
> CometChat.createGroup(group,object :CometChat.CallbackListener<Group>(){
> override fun onSuccess(p0: Group?) {
>   Log.d(TAG, "Group created successfully: " + p0?.toString())
> }
> override fun onError(p0: CometChatException?) {
>   Log.d(TAG, "Group creation failed with exception: " + p0?.message)
> }
> })
> ```

The `createGroup()` method takes the following parameters:

| Parameter | Description |
| - | - |
| `group` | An instance of `Group` class |

After the successful creation of the group, you will receive an instance of the `Group` class which contains all the information about the particular group.

> [!WARNING]
>
> GUID can be alphanumeric with underscore and hyphen. Spaces, punctuation, and other special characters are not allowed.

## Add members while creating a group

You can create a group and add members at the same time using the `createGroupWithMembers()` method. This method takes the [`Group`](https://www.cometchat.com/docs/sdk/reference/entities#group) object, an array of [`GroupMember`](https://www.cometchat.com/docs/sdk/reference/entities#groupmember) objects to be added, and an array of `UIDs` to be banned.

To create an object of the `Group` class, you can use either of the following constructors:

1. `new Group(String GUID, String name, String groupType, String password)`
2. `new Group(String GUID, String name, String groupType, String password, String icon, String description)`

The `groupType` needs to be one of the following values:

1. `CometChat.GROUP_TYPE.PUBLIC`
2. `CometChat.GROUP_TYPE.PASSWORD`
3. `CometChat.GROUP_TYPE.PRIVATE`

To create an object of the [`GroupMember`](https://www.cometchat.com/docs/sdk/reference/entities#groupmember) class, you can use the following constructor:

* `new GroupMember(String UID, String scope)`

> [tab] Java
>
> ```java theme={null}
> Group group = new Group("test_1", "Test 1", CometChatConstants.GROUP_TYPE_PUBLIC,null);
>
> List<GroupMember> groupMembers = new ArrayList<>();
> groupMembers.add(new GroupMember("cometchat-uid-1",CometChatConstants.SCOPE_ADMIN));
> groupMembers.add(new GroupMember("cometchat-uid-2",CometChatConstants.SCOPE_MODERATOR));
> groupMembers.add(new GroupMember("cometchat-uid-3",CometChatConstants.SCOPE_PARTICIPANT));
>
> List<String> bannedUIDs = new ArrayList<>();
> bannedUIDs.add("cometchat-uid-4");
>
> CometChat.createGroupWithMembers(group, groupMembers, bannedUIDs, new CometChat.CreateGroupWithMembersListener() {
> @Override
> public void onSuccess(Group group, HashMap<String, String> hashMap) {
>   Logger.error(TAG, group.toString());
>   Logger.error(TAG, hashMap.toString());
> }
>
> @Override
> public void onError(CometChatException e) {
>   Logger.error(TAG, e.getMessage());
> }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val group = Group("test_1", "Test 1", CometChatConstants.GROUP_TYPE_PUBLIC, null)
>
> val groupMembers: MutableList<GroupMember> = ArrayList()
> groupMembers.add(GroupMember("cometchat-uid-1", CometChatConstants.SCOPE_ADMIN))
> groupMembers.add(GroupMember("cometchat-uid-2", CometChatConstants.SCOPE_MODERATOR))
> groupMembers.add(GroupMember("cometchat-uid-3", CometChatConstants.SCOPE_PARTICIPANT))
>
> val bannedUIDs: MutableList<String> = ArrayList()
> bannedUIDs.add("cometchat-uid-4")
>
> CometChat.createGroupWithMembers(
> group,
> groupMembers,
> bannedUIDs,
> object : CreateGroupWithMembersListener() {
>   override fun onSuccess(group: Group, hashMap: HashMap<String?, String?>) {
>     Logger.error(TAG, group.toString())
>     Logger.error(TAG, hashMap.toString())
>   }
>
>   override fun onError(e: CometChatException) {
>     Logger.error(TAG, e.message)
>   }
> })
> ```

The `onSuccess()` block of this method provides you with 2 sets of information:

1. `Group`: The group object containing information about the group that was created.
2. `HashMap<String, String>`: A HashMap that contains the UID of the user that was supposed to be added as the key and `success` or an error message as the value.

## Group Class

| Field | Editable | Information |
| - | - | - |
| guid | Needs to be specified at group creation. Cannot be edited later | A unique identifier for a group |
| name | Yes | Name of the group |
| type | No | Type of the group: Can be 1. Public 2. Password 3. Private |
| password | No | Password for the group in case the group is of type password. |
| icon | Yes | An URL to group icon |
| description | Yes | Description about the group |
| owner | Yes | UID of the owner of the group. |
| metadata | Yes | Additional data for the group as JSON |
| createdAt | No | The unix timestamp of the time the group was created |
| updatedAt | No | The unix timestamp of the time the group was last updated |
| hasJoined | No | A boolean to determine if the logged in user is a member of the group. |
| joinedAt | No | The unix timestamp of the time the logged in user joined the group. |
| scope | Yes | Scope of the logged in user. Can be: 1. Admin 2. Moderator 3. Participant |
| membersCount | No | The number of members in the groups |
| tags | Yes | A list of tags to identify specific groups. |

## Group Payload Structure

> [accordion] Group Object
>
> The `Group` object returned by SDK methods contains the following fields:
>
> | Parameter | Type | Description |
> | - | - | - |
> | `guid` | String | Unique identifier of the group |
> | `name` | String | Display name of the group |
> | `type` | String | Group type. Values: `"public"`, `"private"`, `"password"` |
> | `password` | String | Password for protected groups (null for public/private groups) |
> | `icon` | String | URL to group icon image |
> | `description` | String | Description of the group |
> | `owner` | String | UID of the group owner |
> | `metadata` | JSONObject | Custom data set by developer. Can contain any key-value pairs |
> | `createdAt` | long | Unix timestamp when group was created |
> | `updatedAt` | long | Unix timestamp of last group update |
> | `hasJoined` | boolean | Whether the logged-in user has joined this group |
> | `joinedAt` | long | Unix timestamp when logged-in user joined the group |
> | `scope` | String | Logged-in user's scope in group. Values: `"admin"`, `"moderator"`, `"participant"` |
> | `membersCount` | int | Total number of members in the group |
> | `tags` | Array\<String> | List of tags for group identification and filtering |
> | `isBannedFromGroup` | boolean | Whether the logged-in user is banned from this group |
>
> **Sample Group Object:**
>
> ```json theme={null}
> {
>   "guid": "group_123",
>   "name": "Developers",
>   "type": "public",
>   "password": null,
>   "icon": "https://example.com/icon.png",
>   "description": "A group for developers",
>   "owner": "user_123",
>   "metadata": {
>     "category": "tech",
>     "isVerified": true
>   },
>   "createdAt": 1699800000,
>   "updatedAt": 1699900000,
>   "hasJoined": true,
>   "joinedAt": 1699850000,
>   "scope": "admin",
>   "membersCount": 25,
>   "tags": ["official", "support"],
>   "isBannedFromGroup": false
> }
> ```

***

## Next Steps

> [card] [Join Group](https://www.cometchat.com/docs/sdk/android/v4/join-group.md)
>
> Join existing groups to participate in conversations

> [card] [Add Members](https://www.cometchat.com/docs/sdk/android/v4/group-add-members.md)
>
> Add members to your created groups

> [card] [Update Group](https://www.cometchat.com/docs/sdk/android/v4/update-group.md)
>
> Modify group details and settings

> [card] [Send Messages](https://www.cometchat.com/docs/sdk/android/v4/send-message.md)
>
> Start sending messages in your group


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.