AI Agent Component Spec
AI Agent Component Spec
| Field | Value |
|---|---|
| Package | com.cometchat:chat-uikit-android |
| Key components | CometChatUsers, CometChatGroups, CometChatMessageList, CometChatMessageComposer, CometChatMessageHeader |
| Purpose | Enable users to start one-on-one or group chats from a new chat screen with user and group browsing. |
| Related | Users, Groups, Conversations, All Guides |
CometChatUsers + CometChatGroups), providing a seamless flow from your conversation list to a specific chat.
Overview
Users can tap the “+” icon in the conversation toolbar or bottom navigation to:- Browse and search CometChat users.
- Browse and search CometChat groups.
- Select a user or group to launch a chat.
Prerequisites
- Android project with CometChat UIKit Android v5 added in
build.gradle. - CometChat credentials (App ID, Auth Key, Region) initialized.
- Navigation configured:
ConversationActivity→NewChatActivity→MessagesActivity. - Internet and network permissions granted in
AndroidManifest.xml.
Components
| Component / Class | Role |
|---|---|
ConversationActivity | Entry point; hosts “+” icon to launch New Chat screen. |
NewChatActivity | Displays tabbed Users/Groups lists. |
activity_new_chat.xml | Layout defining TabLayout, CometChatUsers, CometChatGroups. |
CometChatUsers | Lists and searches users; exposes setOnItemClick(). |
CometChatGroups | Lists and searches groups; exposes setOnItemClick(). |
UsersRequestBuilder | Configures user query filters (e.g. pagination). |
GroupsRequestBuilder | Configures group query filters (e.g. pagination). |
MessagesActivity | Chat UI for the selected user or group. |
activity_messages.xml | Layout for the chat header, message list, and composer. |
Integration Steps
1. Add Entry Point to New Chat
Show a “+” icon that launchesNewChatActivity.
- Kotlin
- Java
ConversationActivity.kt
2. Implement New Chat Screen
Build a tabbed interface with Users and Groups lists.- Kotlin
- Java
NewChatActivity.kt
3. Handle User or Group Selection
LaunchMessagesActivity when an item is tapped.
- Kotlin
- Java
NewChatActivity.kt
4. Open the Messages Screen
Read intent extras and configure chat UI.- Kotlin
- Java
MessagesActivity.kt
Implementation Flow
- User taps the “+” icon →
NewChatActivitylaunches. - Tabs switch between Users and Groups.
- Selection triggers
MessagesActivitywith JSON payload. - Chat UI initializes with the passed user/group.
- Real-time messaging begins via the UI Kit.
Customization Options
- Styling: Apply
cometchatThemeattributes toTabLayoutand list items. - Filtering: Customize
UsersRequestBuilder/GroupsRequestBuilder(e.g.,hideBlockedUsers(true)). - Navigation: Replace default
MessagesActivitywith a custom screen. - Layout Tweaks: Use
android:fitsSystemWindows="true"to avoid overlap.
Filtering & Edge Cases
- Empty States: Built-in empty views in
CometChatUsersandCometChatGroups. - Protected Groups: Prompt for password or disable selection.
- Network Errors: Observe error callbacks and show
Snackbarmessages.
Error Handling
- Default loading and error states are handled by the UI Kit.
- Attach observers on
CometChatUsers/CometChatGroupsto handle failures. - Use Toast or Snackbar for custom error feedback.
Summary / Feature Matrix
| Feature | Component / Method | File(s) |
|---|---|---|
| Launch New Chat screen | Menu item click in ConversationActivity | ConversationActivity.java |
| Tabbed lists | TabLayout + ViewPager2 | activity_new_chat.xml |
| List/search users | CometChatUsers + UsersRequestBuilder | activity_new_chat.xml |
| List/search groups | CometChatGroups + GroupsRequestBuilder | activity_new_chat.xml |
| Selection handling | setOnItemClick() | NewChatActivity.java |
| Initialize chat | messageHeader, messageList, composer | MessagesActivity.java, activity_messages.xml |
Next Steps & Further Reading
Android Sample App (Java)
Explore this feature in the CometChat SampleApp:
GitHub → SampleApp
Android Sample App (Kotlin)
Explore this feature in the CometChat SampleApp:
GitHub → SampleApp