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

Create a channel

Copy link

Two basic types of channels you can create with Sendbird Chat SDK are open channels and group channels.

An open channel is ideal for use cases that don't require a permanent membership in the channel, such as short-lived live events and news-feed style messaging to a massive audience. On the other hand, a group channel is suitable for closer interactions among a limited number of users. To learn more about the different use cases and characteristics of open and group channels, see the channel overview page.

When creating a channel, you can append additional information like cover image, description, and URL by passing several arguments to the corresponding parameters. The channel URL can only contain numbers, letters, underscores, or hyphens, and the URL's length must be between 4 and 100 characters. If you don't specify the channelUrl property, a URL is automatically generated.

If you want to create and continue to use a single group channel for a 1-to-1 chat, set the isDistinct property of the channel to true. Otherwise, if the isDistinct property is set to false, multiple 1-to-1 channels, each with their own chat history and data, may be created for the same two users even if a channel already exists between them.


Open channel

Copy link

You can create an open channel by passing a configured OpenChannelCreateParams object as an argument to the parameter in the createChannel() method like the following.

KotlinKTX
val listOfOperatorUserIds = listOf("Jeff")
val params = OpenChannelCreateParams().apply {
    name = NAME
    channelUrl = UNIQUE_CHANNEL_URL
    coverImage = COVER_IMAGE            // Or coverUrl = COVER_URL
    operatorUserIds = listOfOperatorUserIds         // Or operators = listOfOperators
    data = DATA
}

OpenChannel.createChannel(params) { channel, e ->
    if (e != null) {
        // Handle error.
    }

    if (channel != null) {
        // An open channel of the specified users is successfully created.
        // You can get the open channel's data from the result object of the callback handler.

        val channelUrl = channel.url
    }
    // ...
}

OpenChannelCreateParams

Copy link

This table only contains properties shown in the code above. See the API reference for a complete list of properties.

Property nameTypeDescription

name

string

Specifies the channel topic or the name of the channel.

channelUrl

string

Specifies the URL of the channel. Only numbers, letters, underscores, and hyphens are allowed. The length must be between 4 and 100 characters. If the channelUrl property isn't specified, a URL is automatically generated.

coverImage

file

Uploads a file for the cover image of the channel. Alternatively, you can upload a URL for the cover image of the channel using the coverURL property.

operatorUserIds

list of strings

Specifies a list of one or more users to register as operators of the channel. Operators can delete or edit any messages and view all messages in the channel without filtering or throttling.

data

string

Specifies additional channel information such as a long description of the channel or JSON formatted string.


Group channel

Copy link

You can create a group channel by passing a configured GroupChannelCreateParams object as an argument to the parameter in the createChannel() method like the following.

KotlinKTX
val params = GroupChannelCreateParams().apply {
    name = NAME
    coverUrl = COVER_IMAGE_URL
    userIds = USER_IDS
    isDistinct = IS_DISTINCT
    customType = CUSTOM_TYPE
}

GroupChannel.createChannel(params) { channel, e ->
    if (e != null) {
        // Handle error.
    }

    if (channel != null) {
        // A group channel with the specified configuration is successfully created.
        // You can get the group channel's data from the result object of the callback handler.

        val channelUrl = channel.url
    }
    // ...
}

GroupChannelCreateParams

Copy link

This table only contains properties shown in the code above. See the API reference for a complete list of properties.

Property nameTypeDescription

name

string

Specifies the name of the channel.

coverUrl

string

Specifies the cover image URL of the channel.

userIds

list of strings

Specifies a list of one or more IDs of the users to invite to the channel.

isDistinct

boolean

Determines whether to reuse an existing channel or create a new channel. Setting this property to true returns a channel with the same users in USER_IDS or creates a new channel if no match is found. If set to false, the Sendbird server always creates a new channel with the specified combination of users as well as the channel custom type.

* You can also use this property in conjunction with CUSTOM_TYPE and USER_IDS to create distinct channels for a specified channel custom type and a set of specified users. In order to enable the functionality, visit this page and contact us on Sendbird Dashboard.

customType

string

Specifies the custom channel type which is used for channel grouping.

Note: You can also use the Chat API to create open channels and group channels. For group channels, using the Chat API helps you control channel member invitations on your server side.


Supergroup channel

Copy link

Creating a Supergroup channel follows the same process as creating a group channel with one exception of the isSuper property. The GroupChannelCreateParams class has the isSuper property that determines whether a newly created channel is a Supergroup channel or a regular group channel. Set isSuper to true to create a new Supergroup channel.

Because the distinct option isn't available for Supergroup channels, the isDistinct property is set to false by default when creating a Supergroup channel.

KotlinKTX
val params = GroupChannelCreateParams().apply {
    users = USERS
    isSuper = true
}

GroupChannel.createChannel(params) { channel, e ->
    if (e != null) {
        // Handle error.
    }

    // A group channel of the specified users is successfully created.
    // Through the groupChannel parameter of the callback handler,
    // you can get the group channel's data from the result object that
    // the the Sendbird server has passed to the callback method.

    val channelUrl = channel?.url
}