Skip to main content

Create a Group

Use createGroup() with a Group object. The groupType must be one of:
  1. CometChatConstants.GROUP_TYPE_PUBLIC
  2. CometChatConstants.GROUP_TYPE_PASSWORD
  3. CometChatConstants.GROUP_TYPE_PRIVATE
The createGroup() method takes the following parameters: 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.
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 object, an array of 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 class, you can use the following constructor:
  • new GroupMember(String UID, String scope)
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

Group Payload Structure

The Group object returned by SDK methods contains the following fields:Sample Group Object:

Next Steps

Join Group

Join existing groups to participate in conversations

Add Members

Add members to your created groups

Update Group

Modify group details and settings

Send Messages

Start sending messages in your group