> ## 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.

# Retrieve Groups

> Fetch and filter CometChat groups with the Android SDK using request builders, tags, joined groups, and search.

> [accordion] AI Integration Quick Reference
>
> ```kotlin theme={null}
> // Fetch groups with filters
> val groupsRequest = GroupsRequestBuilder()
>     .setLimit(30)
>     .joinedOnly(true)
>     .setSearchKeyWord("search")
>     .build()
>
> groupsRequest.fetchNext(object : CallbackListener<List<Group>>() {
>     override fun onSuccess(groups: List<Group>) { }
>     override fun onError(e: CometChatException) { }
> })
>
> // Get specific group details
> CometChat.getGroup("GUID", callback)
> ```

## Retrieve List of Groups

Use `GroupsRequestBuilder` to configure filters, then call `fetchNext()` to retrieve groups.

### Set Limit

Set the number of groups to fetch per request.

> [tab] Java
>
> ```java theme={null}
> GroupsRequest groupsRequest = new GroupsRequest.GroupsRequestBuilder()
> .setLimit(limit)
> .build();
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val groupsRequest = GroupsRequestBuilder()
> .setLimit(limit)
> .build()  
> ```

### Set Search Keyword

Filter groups by a search string.

> [tab] Java
>
> ```java theme={null}
> GroupsRequest groupsRequest = new GroupsRequest.GroupsRequestBuilder()
> .setSearchKeyWord("abc")
> .build();
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val groupsRequest = GroupsRequestBuilder()
> .setSearchKeyWord("abc")
> .build()
> ```

### Joined Only

Return only groups the logged-in user has joined.

> [tab] Java
>
> ```java theme={null}
> GroupsRequest groupsRequest = new GroupsRequest.GroupsRequestBuilder()
> .joinedOnly(true)
> .build();
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val groupsRequest = GroupsRequestBuilder()
> .joinedOnly(true)
> .build()  
> ```

### Set Tags

Filter groups by tags. Only groups tagged with the specified tags are returned.

> [tab] Java
>
> ```java theme={null}
> List<String> tags = new ArrayList<>();
> tags.add("tag1");
> tags.add("tag2");
> GroupsRequest groupsRequest = new GroupsRequest.GroupsRequestBuilder()
> .setLimit(limit)
> .setTags(tags)
> .build();  
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val tags: MutableList<String> = ArrayList()
> tags.add("tag1")
> tags.add("tag2")
> val groupsRequest = GroupsRequestBuilder()
> .setLimit(limit)
> .setTags(tags)
> .build()
> ```

### With Tags

Include tag data in the response when set to `true`.

> [tab] Java
>
> ```java theme={null}
> GroupsRequest groupsRequest = new GroupsRequest.GroupsRequestBuilder()
> .setLimit(limit)
> .withTags(true)
> .build();
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val groupsRequest = GroupsRequestBuilder()
> .setLimit(limit)
> .withTags(true)
> .build()
> ```

### Fetch Groups

After configuring the builder, call `build()` then `fetchNext()` to retrieve groups. Public and password-protected groups are always included. Private groups only appear if the user is a member.

> [tab] Java
>
> ```java theme={null}
> private GroupsRequest groupsRequest = null;
> private int limit = 30;
>
> groupsRequest = new GroupsRequest.GroupsRequestBuilder().setLimit(limit).build();
>
> groupsRequest.fetchNext(new CometChat.CallbackListener<List<Group>>() {
> @Override
> public void onSuccess(List <Group> list) {
>   Log.d(TAG, "Groups list fetched successfully: " + list.size());
> }
> @Override
> public void onError(CometChatException e) {
>   Log.d(TAG, "Groups list fetching failed with exception: " + e.getMessage());
> }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val limit = 30
> val groupsRequest = GroupsRequestBuilder().setLimit(limit).build()
>
> groupsRequest.fetchNext(object : CallbackListener<List<Group?>>() {
> override fun onSuccess(list: List<Group?>) {
>   Log.d(TAG, "Groups list fetched successfully: " + list.size)
> }
>
> override fun onError(e: CometChatException) {
>   Log.d(TAG, "Groups list fetching failed with exception: " + e.message)
> }
> })
> ```

## Retrieve Particular Group Details

Use `getGroup()` to fetch details for a specific group by GUID.

> [tab] Java
>
> ```java theme={null}
> private String GUID = "GUID";
>
> CometChat.getGroup(GUID, new CometChat.CallbackListener<Group>() {
> @Override
> public void onSuccess(Group group) {
>   Log.d(TAG, "Group details fetched successfully: " + group.toString());        
> }
>
> @Override
> public void onError(CometChatException e) { 
>   Log.d(TAG, "Group details fetching failed with exception: " + e.getMessage());   
>
> }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val GUID : String = "GUID"
>
> CometChat.getGroup(GUID,object :CometChat.CallbackListener<Group>(){
> override fun onSuccess(p0: Group?) {
>   Log.d(TAG, "Group details fetched successfully: " + p0?.toString())
> }
> override fun onError(p0: CometChatException?) {
>   Log.d(TAG, "Group details fetching failed with exception: " +p0?.message)
> }
> })
> ```

| Parameter | Description |
| - | - |
| `GUID` | The GUID of the group for whom the details are to be fetched |

On success, the [`Group`](https://www.cometchat.com/docs/sdk/reference/entities#group) object containing the details of the group is returned.

## Get Online Group Member Count

Use `getOnlineGroupMemberCount()` to get the count of online members for specific groups.

> [tab] Java
>
> ```java theme={null}
> List<String> guids = new ArrayList<>();
> guids.add("cometchat-guid-1");
> guids.add("cometchat-guid-11");
>
> CometChat.getOnlineGroupMemberCount(guids, new CometChat.CallbackListener<HashMap<String, Integer>>() {
> @Override
> public void onSuccess(HashMap<String, Integer> stringIntegerHashMap) {
>   Log.d(TAG, "Online count fetched successfully " + stringIntegerHashMap.toString());
> }
>
> @Override
> public void onError(CometChatException e) {
>   Log.d(TAG, e.getMessage());
> }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val guids: MutableList<String> = ArrayList()
> guids.add("cometchat-guid-1")
> guids.add("cometchat-guid-11")
>
> CometChat.getOnlineGroupMemberCount(guids, object : CallbackListener<HashMap<String?, Int?>>() {
> override fun onSuccess(stringIntegerHashMap: HashMap<String?, Int?>) {
>   Log.d(TAG, "Online count fetched successfully $stringIntegerHashMap")
> }
>
> override fun onError(e: CometChatException) {
>   Log.d(TAG, e.message!!)
> }
> })
> ```

This method returns a `Hashmap` with the GUID of the group as the key and the online member count for that group as the value.

## 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] [Create Group](https://www.cometchat.com/docs/sdk/android/create-group.md)
>
> Create new groups for your users

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

> [card] [Retrieve Members](https://www.cometchat.com/docs/sdk/android/retrieve-group-members.md)
>
> Fetch list of group members

> [card] [Additional Filtering](https://www.cometchat.com/docs/sdk/android/additional-message-filtering.md)
>
> Learn more about advanced filtering options


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