Chat / Android
Chat Android v4
Chat Android
Chat
Android
Home
/
Chat
/
Android
/
Channel
This is the new Docs for Chat SDK v4 for Android. To see the previous Docs, click here.

Retrieve a list of channels

You can retrieve a list of OpenChannel objects using the next() method of an OpenChannelListQuery instance and a list of GroupChannel objects using the next() method of a GroupChannelListQuery instance. The GroupChannelListQuery instance returns both public and private group channels that the current user has joined. To retrieve a list of all public group channels regardless of membership status, use the PublicGroupChannelListQuery instance as described later on this page.

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


Open channels

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

Create a GroupChannelListQuery instance to retrieve a list of group channels matching the specifications set by GroupChannelListQueryParams.

You can set the GroupChannelListQueryParams's includeEmpty property to true to allow users to view empty channels, which include channels that are empty because the view chat history option is turned off to prevent new members from seeing previous conversations. You can determine whether to turn on the chat history option on Sendbird Dashboard under Settings > Chat > Channels > Group channels.

After a list of group channels is successfully retrieved, you can access the data of each channel from the result list through the channels parameter of the callback handler.

val query = GroupChannel.createMyGroupChannelListQuery(
    GroupChannelListQueryParams().apply {
        includeEmpty = true
        myMemberStateFilter = MyMemberStateFilter.JOINED // Another acceptable value is INVITED.
        order = GroupChannelListQueryOrder.LATEST_LAST_MESSAGE // Other acceptable values include CHRONOLOGICAL, LATEST_LAST_MESSAGE, CHANNEL_NAME_ALPHABETICAL, and METADATA_VALUE_ALPHABETICAL.
        limit = 15
    }
)
query.next { channels, e ->
    if (e != null) {
        // Handle error.
    }
}

All public group channels

If you want to retrieve a list of all public group channels regardless of the current user's membership status, use the PublicGroupChannelListQuery instance and set membershipFilter to MembershipFilter.ALL in PublicGroupChannelListQueryParams.

After a list of public group channels is successfully retrieved, you can access the data of each channel from the result list through the channels parameter of the callback handler.

val query = GroupChannel.createPublicGroupChannelListQuery(
    PublicGroupChannelListQueryParams().apply {
        includeEmpty = true
        membershipFilter = MembershipFilter.ALL
        order = GroupChannelListQueryOrder.CHANNEL_NAME_ALPHABETICAL // Other acceptable values are CHRONOLOGICAL, CHANNEL_NAME_ALPHABETICAL, and METADATA_VALUE_ALPHABETICAL.
        limit = 15
    }
)
query.next { channels, e ->
    if (e != null) {
        // Handle error.
    }
}

Supergroup channels

To retrieve a list of Supergroup channels, you can set the superChannelFilter property to SuperChannelFilter.SUPER_CHANNEL_ONLY in either the GroupChannelListQuery or PublicGroupChannelListQuery instance. The superChannelFilter property works much like other search filters. Use GroupChannelListQuery when only searching for group channels that the current user belongs to, and use PublicGroupChannelListQuery when searching for all public group channels regardless of the current user's membership status.

When queried channels are returned, you can check if the channel is a Supergroup channel by looking at whether the isSuper property has a value of true.

Using GroupChannelListQuery

val query = GroupChannel.createMyGroupChannelListQuery(
    GroupChannelListQueryParams().apply {
        superChannelFilter = SuperChannelFilter.SUPER_CHANNEL_ONLY
    }
)
query.next { channels, e ->
    if (e != null) {
        // Handle error.
    }
}

Using PublicGroupChannelListQuery

val query = GroupChannel.createPublicGroupChannelListQuery(
    PublicGroupChannelListQueryParams().apply {
        superChannelFilter = SuperChannelFilter.SUPER_CHANNEL_ONLY
    }
)
query.next { channels, e ->
    if (e != null) {
        // Handle error.
    }
}