Skip to main content

Create a Group

In other words, as a logged-in user, how do I create a public, private or password-protected group? You can create a group using createGroup() method. This method takes a Group object as a parameter that takes all the information related to the group. So, in order to create a group, you will have to create an object of the group and assign all the values to the group. To create a group, you can use either of the below two initializers:
  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 either of the below 3 values: 1.CometChatConstants.GROUP_TYPE_PUBLIC (public) 2.CometChatConstants.GROUP_TYPE_PASSWORD (password) 3.CometChatConstants.GROUP_TYPE_PRIVATE (private)
The createGroup() method takes the following parameters: After the successful creation of the group, you will receive an instance of 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, Array of Group Member Object to be added & Array of UIDs to be banned. To create an object of Group class, you can use either of the below two 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 either of the below 3 values:
  1. CometChat.GROUP_TYPE.PUBLIC
  2. CometChat.GROUP_TYPE.PASSWORD
  3. CometChat.GROUP_TYPE.PRIVATE
To create an object of Group Member class, you can use the below constructor:
  • new CometChat.GroupMember(String UID, String scope)

Group Class