Home
/
UIKit
/
Android

Send your first message

Sendbird UIKit for Android is a set of prebuilt UI components that allows you to easily craft an in-app chat with all the essential messaging features. Our development kit includes light and dark themes, text fonts, colors and more. You can customize these components to create an interactive messaging interface unique to your brand identity.

Sendbird UIKit supports both open channels and group channels. Follow the guide below to start sending a message from scratch using Java or Kotlin.


Requirements

The minimum requirements for UIKit for Android are:

  • Android 4.1 (API level 16) or higher
  • Java 8
  • Support androidx only
  • Gradle 4.0.1 or higher

Before you start

Before installing Sendbird Chat SDK, you need to create a Sendbird application on the Sendbird Dashboard, which comprises everything required in a chat service including users, messages, and channels. You will need the App ID of your Sendbird application when initializing the Chat SDK.

Note: Each Sendbird application can be integrated with a single client app. Within the same application, users can communicate with each other across all platforms, whether they are on mobile devices or on the web.


Get started

You can start building a modern messaging experience in your app by installing Sendbird UIKit. This developer kit is an add-on feature to Sendbird Chat SDK so installing it will also install the core Chat SDK.

Step 1 Create a project

To get started, open Android Studio and create a new project for UIKit in the Project window as follows:

  1. Click Start a new Android Studio project in the Welcome to Android Studio window.
  2. Select Empty Activity in the Select a Project Template window and click Next.
  3. Enter your project name in the Name field in the Configure your project window.
  4. Select your language as either Java or Kotlin from the Language drop-down menu.
  5. Enable Use androidx.*artifacts.
  6. Select minimum API level as 16 or higher.

Step 2 Install UIKit

You can install UIKit for Android through Gradle. Begin by opening the root build.gradle file and add the code blocks below:

build.gradle
Light Color Skin
Copy
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        // Don't place your application dependencies here.
        // They belong to the individual module build.gradle files.
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }  // Add this line.
        maven { url "https://repo.sendbird.com/public/maven" }  // Add this line.
    }
}

Note: Make sure the code blocks above aren't added to your module build.gradle file.

Next, open the build.gradle file at the application level. For both Java and Kotlin, add the code blocks and dependencies as follows:

build.gradle
Light Color Skin
Copy
apply plugin: 'com.android.application'

android {
    ...

    dataBinding {
        enabled = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8    // Make sure you have JavaVersion 1.8.
        targetCompatibility JavaVersion.VERSION_1_8    // Make sure you have JavaVersion 1.8.
    }

    ...
}

dependencies {
    ...
    implementation 'com.sendbird.sdk:uikit:2.1.8'
    ...
}

Before saving the build.gradle file, check if you’ve enabled dataBinding. Then, click the Sync button to apply all changes.

Note: UIKit SDK versions 2.1.1 or lower can be downloaded from JCenter until February 1, 2022. SDK versions higher than 2.1.1 will be available on Sendbird's remote repository.

Step 3 Initialize SendbirdUIKit instance

To integrate and run Sendbird UIKit in your app, you need to initialize it first. You can initialize SendBirdUIKit instance by passing the SendBirdUIKitAdapter instance as an argument to a parameter in the SendBirdUIKit.init() method. The SendBirdUIKit.init() must be called once in the onCreate() method of your app’s Application instance.

Light Color Skin
Copy
package com.example.uikitapplication;

import android.app.Application;

import com.sendbird.uikit.SendBirdUIKit;
import com.sendbird.uikit.adapter.SendBirdUIKitAdapter;
import com.sendbird.uikit.interfaces.UserInfo;

public class BaseApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        SendBirdUIKit.init(new SendBirdUIKitAdapter() {
            @Override
            public String getAppId() {
                return YOUR_APP_ID;  // Specify your Sendbird application ID.
            }

            @Override
            public String getAccessToken() {
                return "";
            }

            @Override
            public UserInfo getUserInfo() {
                return new UserInfo() {
                    @Override
                    public String getUserId() {
                        return USER_ID;  // Specify your user ID.
                    }

                    @Override
                    public String getNickname() {
                        return USER_NICKNAME;  // Specify your user nickname.
                    }

                    @Override
                    public String getProfileUrl() {
                        return "";
                    }
                };
            }
        }, this);
    }
}

Step 4 Add BaseApplication

Add the created BaseApplication to AndroidManifest.xml.

Light Color Skin
Copy
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sendbird.uikitapplication">

    <application
        android:name=".BaseApplication"  // Add this line.
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                ...
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

Step 5 Display channel list

ChannelListActivity is the starting point for launching UIKit in your application. By implementing the code below, you will see a complete list of group channels that you're a member of.

Light Color Skin
Copy
package com.example.uikitapplication;

import com.sendbird.uikit.activities.ChannelListActivity;

public class MainActivity extends ChannelListActivity {
    // Add this line.
    // If you’re going to inherit `ChannelListActivity`, don’t implement `setContentView()` in the activity.
}

Step 6 Send your first message

You can now run the application on an emulator or a plugged-in device. To send a message, you must first create a group channel by clicking on the icon in the top-right corner. Then, you can select users you wish to invite as members to your channel. Once the channel has been created, type your first message and press send.

You've successfully sent your first message with Sendbird.

Note: To customize your user list instead of retrieving the entire list from Sendbird server, set the custom user list query handler.


UIKit components

Methods provided by Sendbird UIKit for Android automatically process data using our Chat SDK. Using Activities and Fragments, chat can easily be added to your Android client app using the components below.

SendBirdUIKit instance

This is the most important class in the UIKit. These interfaces can be used to initialize information and call all Activity components.

List of methods

MethodDescription

init()

Initializes a SendBirdUIKit instance.

setDefaultTheme()

Sets a theme as the default theme.

getDefaultTheme()

Retrieves the default theme.

isDarkMode()

Determines whether the theme mode is ThemeMode.Dark

getAdapter()

Retrieves the current registered SendBirdUIKit adapter.

setCustomUserListQueryHandler()

Imports your custom user list. If this isn’t implemented, the list of all users in the Sendbird server are displayed.

connect()

Connects to Sendbird server and update your profile.

disconnect()

Disconnects from Sendbird server.

updateUserInfo()

Updates user information for profile display.

setCustomParamsHandler()

Sets the handler for common custom.

getCustomParamsHandler()

Returns the custom params handler.

setUseDefaultUserProfile()

Determines whether the user profile is used.

shouldUseDefaultUserProfile()

Returns the set value regarding the use of user profile.

setUseImageCompression()

Determines whether to compress the image when sending an image file message. This method only applies to the following image types: image/jpg, image/jpeg, and image/png. (Default: false)

shouldUseImageCompression()

Retrieves the set value of setUseImageCompression() on whether the image should be compressed when sending it as an image file message.

setCompressQuality()

Sets the value of the compression rate to apply to the image. Acceptable values are 0 to 100, inclusive. (Default: 100)

getCompressQuality()

Retrieves the set value of the compression rate to apply to the image.

setResizingSize()

Sets the new width and height to apply to the image. The given value is shown in the order of the width first, then the height. (Default: 1080x1920)

* When displaying the compressed image as a thumbnail, the value of the new width and height will be halved. The minimum value for the compressed thumbnail is 100x100.

getResizingSize()

Retrieves the resized width and height to apply to the image.

SendBirdUIKitAdapter

Listed below are the methods of the SendBirdUIKitAdapter class:

MethodDescription

getAppId()

Retrieves the APP_ID of your Sendbird application.

getUserInfo()

Retrieves the information of the current user

getAccessToken()

Retrieves the access token of the current user, which is required to provide in the SendBirdUIKit.init() method. Using the Platform API, you can create a user along with their own access token, or issue an access token to an existing user. If you don’t want to use an access token, you must specify the return value of the UserInfo.getUserID() in the SendBirdUIKitAdapter.getUserInfo() instead. (Default: USER_ID)

UserInfo

Listed below are the methods of the UserInfo class:

MethodDescription

getUserId()

Retrieves the ID of the current user that has been registered to Sendbird server.

getNickName()

Retrieves the current user's nickname. If the nickname hasn’t been set, USER ID is used instead by default.

getProfileUrl()

Retrieves the URL of the current user's profile image.

Additional components

The UIKit also provides the following components. All components can be called while fragments and activities are running on the Android platform.

List of components

ComponentDescription

ChannelList

Shows all channels a user has joined.

Channel

Shows the current channel a user has joined. From this component, users can send or receive messages.

CreateChannel

Shows all the users of your client app so you can create a channel. Users can be selected from this component to begin chatting.

InviteChannel

Shows all the users of your client app from the current channel so you can invite other users to join.

ChannelSettings

Changes the channel information.

MemberList

Shows the list of members in the current channel.

PromoteOperator

Shows the list of members in the current channel whom you can promote as an operator.

BannedList

Shows the list of members who are banned from the current channel.

Moderation

Shows the list of moderation options for the current channel.

MutedMember

Shows the list of members who are muted in the current channel.

OperatorList

Shows the list of members who are appointed as an operator in the current channel.