Skip to main content
FieldValue
Packagecom.cometchat:chat-uikit-android
Key componentsCometChatSearch, CometChatMessageList, CometChatMessageComposer, CometChatMessageHeader
PurposeFull-text message search across conversations with result routing and navigation
Sample appGitHub
RelatedAll Guides
Search Messages lets users locate specific messages across conversations and groups using keyword search, then navigate directly to the result. Before starting, complete the Getting Started guide.

Components

Component / ClassRole
CometChatSearchMain search interface with filter chips and result lists
CometChatMessageListDisplays messages in the selected conversation
CometChatMessageComposerMessage input for the selected conversation
CometChatMessageHeaderHeader bar showing conversation context

Integration Steps

1. Add CometChatSearch to your layout

activity_search.xml
<com.cometchat.chatuikit.search.CometChatSearch
    android:id="@+id/cometchat_search"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

2. Handle conversation result clicks

When a user taps a conversation result, navigate to the message view for that conversation.
SearchActivity.kt
val search: CometChatSearch = findViewById(R.id.cometchat_search)

search.setOnConversationClicked { view, position, conversation ->
    val intent = Intent(this, ChatActivity::class.java)
    intent.putExtra("conversation", conversation)
    startActivity(intent)
}
File: SearchActivity

3. Handle message result clicks

When a user taps a message result, navigate to the conversation and scroll to that message using setMessageId() on the message list.
SearchActivity.kt
search.setOnMessageClicked { view, position, message ->
    val intent = Intent(this, ChatActivity::class.java)
    if (message.receiverType == CometChatConstants.RECEIVER_TYPE_USER) {
        intent.putExtra("uid", (message.receiver as User).uid)
    } else {
        intent.putExtra("guid", (message.receiver as Group).guid)
    }
    intent.putExtra("messageId", message.id)
    startActivity(intent)
}
File: SearchActivity

4. Scope search to a specific conversation (optional)

Restrict search results to a single user or group conversation.
// Scope to a specific user conversation
search.setUid("alice-uid")

// Or scope to a specific group conversation
search.setGuid("group-guid")

5. Configure search filters (optional)

Control which filter chips appear and which is selected by default.
search.setSearchFilters(
    listOf(
        UIKitConstants.SearchFilter.MESSAGES,
        UIKitConstants.SearchFilter.CONVERSATIONS
    )
)
search.setInitialSearchFilter(UIKitConstants.SearchFilter.MESSAGES)

Feature Matrix

FeatureComponent / MethodFile
Search interfaceCometChatSearchSearchActivity
Conversation resultssetOnConversationClickedSearchActivity
Message resultssetOnMessageClickedSearchActivity
Scoped searchsetUid / setGuidSearchActivity
Filter chipssetSearchFilters / setInitialSearchFilterSearchActivity

Next Steps