Build in-app chat using Kotlin – Part 1

1. Intro This guide is an easy to follow Kotlin implementation guide to build a chat application using the Sendbird Chat Core SDK. The full guide includes two parts. After completing it, you will have created your very own chat application with Kotlin. In this first part, the guide covers initialization, log in; and the display, selection, and creation of channels. Sendbird has two channel types: Open Channels and Group Channels. This guide focuses on Group Channel implementation to create 1:1 private chats and private group chats. This guide creates three activities: LoginActivity – A basic Login screen for users to login and set their nickname ChannelListActivity – A channel list to display the group channels that a user can join ChannelCreationActivity – A screen that allows a user to invite other users and create a channel And it covers the following steps: Import dependencies and add permissions Login Activity, including: Creating a basic Login UI Create LoginActivity Displaying a channel list, including: Create a channel list UI Create ChannelListActivity Create ChannelListAdapter for RecyclerView Creating Channels, including: Implement a Channel Create UI Implement ChannelCreateActivity Implement ChannelCreateAdapter for RecyclerView 2. Import dependencies and add permissions First, add the most recent Sendbird SDK to the app level build.gradle file.

3. Login activity To begin chatting, a user must be able to log in or create a user. This section covers two parts, including how to: Initialize the SendBird application with your respective AppID Connect to Sendbird with a UserID, and nickname Creating a basic Login UI The basic sign in UI includes an Edit Text field for the UserID, one for the desired nickname, and a button to connect. See the image below.

You can view the full code here:


Create LoginActivity

Create a new Activity called LoginActivity.kt. Be sure to register this activity in the manifest. This activity is responsible for initializing and handling the connection to your SendBird application.

Ideally, you would choose to put the initialization in a different activity. For the sake of simplicity, we’ll initialize in the LoginActivity.

Add an onCreate method. This method handles both the UI elements and initialization process.

onCreate method in LoginActivity.kt

The connectToSendBird() method connects a passed UserID to SendBird, and then updates the Nickname of the connected user. Upon completion it launches our ChannelListActivity.

connectToSendBird() method in LoginActivity.kt

See the following Gist for the complete contents of LoginActivity.kt.

4. Displaying a channel list Once you’ve created the login, create an activity to display, choose, and create Channels. The following shows you how to query a list of channels associated with the User, and render them and display them in a RecyclerView. Create a channel list UI

Next, create a basic item for the channel list RecyclerView. For simplicity, we’ll create a CardView with TextViews for the channel name, member count, and most recent message.


Now, create an actual view that contains the RecyclerView for the Channel List. This view also contains a FloatingActionButton, which enables users to create channels.


Create ChannelListActivity

Next, create a new Activity called

Continue reading

This post was originally published on this site