/ SDKs / Android
SDKs
Chat SDKs Android v4
Chat SDKs Android
Chat SDKs
Android
Version 4

Retrieve a list of channels

Copy link

You can retrieve a list of OpenChannel objects using the next() method of an OpenChannelListQuery instance.

On the other hand, a list of GroupChannel objects can be retrieved through GroupChannelCollection and its loadMore() method. First, create a GroupChannelListQuery instance. The GroupChannelListQuery instance returns both public and private group channels that the current user has joined. To retrieve a list of certain group channels such as public group channels or Supergroup channels, use the the list query's filters as described at the bottom of this page.

Note: You can also search for specific open channels and group channels with keywords and filters.


Open channels

Copy link

Create an OpenChannelListQuery instance to retrieve a list of open channels matching the specifications set by OpenChannelListQueryParams. After a list of open channels is successfully retrieved, you can access the data of each open channel from the result list through the channels parameter of the callback handler.

val query = OpenChannel.createOpenChannelListQuery(OpenChannelListQueryParams())
query.next { channels, e ->
    if (e != null) {
        // Handle error.
    }
}

Group channels

Copy link

A group channel list view can be drawn with a GroupChannelCollection instance. First, create a GroupChannelListQuery instance through the createMyGroupChannelListQuery() method and its query setters. This determines which channel to include in the channel list and how to list channels in order.

To retrieve group channels in the collection, call hasMore first to check whether there are more channels to load for the collection. If so, call loadMore().

To learn more about how the collection works, see Group channel collection under Local caching.

KotlinKTX
// Call hasMore first to check if there are more channels to load.
if (collection.hasMore) {
    collection.loadMore { channels, e ->
        if (e != null) {
            // Handle error.
            return@loadMore
        }

        // Add channels to your data source.
    }
}

Filter group channels using GroupChannelListQuery

Copy link

When creating a GroupChannelCollection instance, you need to set params within GroupChannelListQuery first. The params in GroupChannelListQuery works much like other search options, retrieving a list of group channels matching the specifications set by GroupChannelListQueryParams. For example, use myMemberStateFilter when searching for only the group channels that the current user belongs to, and publicChannelFilter when searching for all public group channels regardless of the current user's membership status. To retrieve a list of Supergroup channels, you can set the superChannelFilter property to SuperChannelFilter.SUPER_CHANNEL_ONLY.

Once the params is set, you can use the query instance for GroupChannelCollectionCreateParams in createGroupChannelCollection().

kotlin
// Create a GroupChannelListQuery instance in GroupChannelCollection.
val query = GroupChannel.createMyGroupChannelListQuery(
    GroupChannelListQueryParams().apply {
        includeEmpty = true
        order = GroupChannelListQueryOrder.CHRONOLOGICAL
        publicChannelFilter = PublicChannelFilter.PUBLIC            // Retrieve public group channels.
        superChannelFilter = SuperChannelFilter.SUPER_CHANNEL_ONLY  // Retrieve Supergroup channels.
        // You can add other params setters.
    }
)