Skip to main content
Quick Reference for AI Agents & Developers
// Join a public group
CometChat.joinGroup("GUID", CometChatConstants.GROUP_TYPE_PUBLIC, "", 
    object : CometChat.CallbackListener<Group>() {
        override fun onSuccess(group: Group) { }
        override fun onError(e: CometChatException) { }
    })

// Join a password-protected group
CometChat.joinGroup("GUID", CometChatConstants.GROUP_TYPE_PASSWORD, "password123", callback)
Available via: SDK | REST API | UI Kits

Join a Group

To start participating in group conversations, you need to join a group. You can do so using the joinGroup() method.
private String GUID = "GUID";
private String groupType = CometChatConstants.GROUP_TYPE_PUBLIC;
private String password = "";

CometChat.joinGroup(GUID, groupType, password, new CometChat.CallbackListener<Group>() {
  @Override
  public void onSuccess(Group joinedGroup) {
    Log.d(TAG, joinedGroup.toString());
  }
  @Override
  public void onError(CometChatException e) {
    Log.d(TAG, "Group joining failed with exception: " + e.getMessage());
  }
});
The joinGroup() method takes the following parameters:
ParameterDescription
GUIDThe GUID of the group you would like to join
groupTypeType of the group. CometChat provides 3 types of groups: 1. CometChatConstants.GROUP_TYPE_PUBLIC (public) 2. CometChatConstants.GROUP_TYPE_PASSWORD (password) 3. CometChatConstants.GROUP_TYPE_PRIVATE (private)
passwordPassword is mandatory for password-protected groups.
Once you have joined a group successfully, you can send and receive messages in that group. CometChat keeps track of the groups you have joined, so you do not need to join the group every time you want to communicate in it. You can identify if a group is joined using the hasJoined parameter in the Group object.

Real-Time Group Member Joined Events

As a member of a group, how do I know if someone joins the group when my app is running? If a user joins any group, the members of the group receive a real-time event in the onGroupMemberJoined() method of the GroupListener class.
CometChat.addGroupListener(UNIQUE_LISTENER_ID, new CometChat.GroupListener() {
  @Override
  public void onGroupMemberJoined(Action action, User joinedUser, Group joinedGroup) {
    Log.d(TAG, "User joined");
  }
});

Missed Group Member Joined Events

As a member of a group, how do I know if someone joins the group when my app is not running? When you retrieve the list of previous messages, if a member has joined any group that the logged-in user is a member of, the list of messages will contain an Action message. An Action message is a sub-class of the BaseMessage class. For the group member joined event, in the Action object received, the following fields can help you get the relevant information:
  1. action - joined
  2. actionBy - User object containing the details of the user who joined the group
  3. actionFor - Group object containing the details of the group the user has joined
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.

Best Practices

Use the hasJoined property of the Group object to avoid attempting to join groups you’re already a member of.
Always prompt users for passwords when joining password-protected groups. Store passwords securely if needed for re-authentication.
Register group listeners to receive real-time notifications when other users join groups you’re a member of.

Troubleshooting

Symptom: joinGroup() fails with “Already a member” error.Cause: User is already a member of the group.Solution: Check the hasJoined property before calling joinGroup(). CometChat tracks joined groups automatically.
Symptom: joinGroup() fails with “Incorrect password” error for password-protected groups.Cause: Wrong password provided for a password-protected group.Solution: Verify the password is correct. Passwords are case-sensitive.
Symptom: joinGroup() fails with “Cannot join private group” error.Cause: Attempting to join a private group without an invitation.Solution: Private groups require an admin or moderator to add members. Use the group-add-members functionality instead.

Next Steps