Quick Start

SendBird helps you to implement real-time chat to any application with speed and efficiency. Our Android SDK provides you with various methods to initialize, configure and build the chat from the client side - no server side implementation required because our reliable infra management service is delivered with the SDK. This section presents a brief overview of the SDK’s functionalities and logic, then let you go through the preliminary steps of implementing SendBird in your own application.


First, try out the sample app!

Our sample app is a fully functional messaging app built upon material design principles. Download and build the sample from GitHub to chat freely with other people. The app gives you a picture of what you can build using SendBird, although it is by no means the limit of its capabilities.

The sample app is a useful reference when developing your own project using SendBird. In fact, a simple way to implement chat is to build your app on top of the sample. Note that you must change the App ID to your own in this case - reference to the Create a new SendBird application from our dashboard section.


How SendBird works with messaging

To build a messaging with the SendBird SDK is simple: a user connects, enters a channel, send a message to the channel, and receives the messages from all other users within the channel. There are two types of channels: Open and Group Channel. Open Channel is a public channel which anyone can enter and chat freely. Group Channel is basically a private channel that a user can join as a new member through an invitation. But it has various properties for its functionalities, so you can make a public group channel working like Open Channel.

When using the SDK, messages are automatically delivered to channel event handlers. As long as an app instance is connected to our server, it receives callbacks to onMessageReceived(), onUserJoined(), and so on, with the message or channel objects containing the latest information, in case of a message incoming or other relevant events happened.


Install and configure Android SDK

Step 1: Create a new SendBird application from our dashboard

A SendBird application comprises everything that goes in a chatting service such as users, messages, and channels. Create a new SendBird application by singing in to our dashboard. Either that, you can sign up with Google, GitHub, or create a new account with the dashboard.

Once you create an application, all users within can communicate with each other, across all platforms. This means users using iOS, Android, and web clients can all chat with one another without any additional setup. However, all data is limited to the scope of one application, meaning users in different SendBird applications cannot talk to each other.

Step 2: Install the SDK

Installing the SDK is simple if you’re familiar with using external libraries or SDK’s in your projects. To install the SendBird SDK using Gradle, add the following lines to build.gradle file at the app level.

build.gradle
repositories {
    maven { url "https://raw.githubusercontent.com/smilefam/SendBird-SDK-Android/master/" }
}
dependencies {
    implementation 'com.sendbird.sdk:sendbird-android-sdk:3.0.83'
}

Alternatively, you can download the .jar file from the link below. Copy this file into your libs/ folder, and make sure you include the library in your build.gradle file as well.

Step 3: Grant system permissions to the SDK

The SendBird SDK requires system permissions. These permissions allow the SDK to communicate with the SendBird server and read/write files to a device's external storage.

Add the following lines to your AndroidManifest.xml file.

AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />

<!-- READ/WRITE_EXTERNAL_STORAGE permissions are required to upload or download files from/into external storage. ->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

(Optional) Step 4: Configure ProGuard for shrinking code and resources

When you build your app apk with minifyEnabled true, add the following line to the module's proguard-rules property file.

-dontwarn com.sendbird.android.shadow.**

Send your first message

The Android SDK abstracts messaging into a simple and straightforward process. To send your first message, do the following steps:

Note: The following methods, excluding SendBird.init(), are asynchronous. This means you must ensure that you've received a success callback to proceed to the next step. A simple way to do this is the nest methods - see the example in Step 4: Enter the channel when channel.enter() is called after receiving an OpenChannel.getChannel() callback.

Step 1: Initialize the SDK

Initialization binds the SDK to Android’s context, thereby allowing it to respond to connection and state changes. Pass in the App ID of the SendBird application you created earlier in our dashboard to initialize the SDK.

Note: The SendBird.init() should be called once across an Android app. We recommend that you perform the SDK initialization in the onCreate() method of Application class.

SendBird.init(APP_ID, Context context);

Step 2: Connect to SendBird server

Connect a user to a SendBird server using their User ID. Any untaken user ID creates a new user in the SendBird application before connecting, while an existing ID makes the user log in directly. Authentication with Access Tokens are discussed in the Authentication section.

SendBird.connect(USER_ID, new ConnectHandler() {
    @Override
    public void onConnected(User user, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

Step 3: Create a new open channel

Create an open channel. Once created, all users in the SendBird application can freely enter the channel to converse.

Note: A group channel can be created in a similar manner. However, to have other users join the channel, an existing member of the channel (for example, the creator) must invite them first.

OpenChannel.createChannel(new OpenChannel.OpenChannelCreateHandler() {
    @Override
    public void onResult(OpenChannel openChannel, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});

Step 4: Enter the channel

Enter the channel to view and send messages.

OpenChannel.getChannel(CHANNEL_URL, new OpenChannel.OpenChannelGetHandler() {
    @Override
    public void onResult(OpenChannel openChannel, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }

        openChannel.enter(new OpenChannel.OpenChannelEnterHandler() {
            @Override
            public void onResult(SendBirdException e) {
                if (e != null) {    // Error.
                    return;
                }
            }
        });
    }
});

Step 5: Send a message to the channel

And finally, send a message to the channel! There are three types of messages: a User Message is a plain text message, a File Message is a binary file, such as an image or PDF, and an Admin Message is a special type of message sent through our dashboard or Platform API.

channel.sendUserMessage(MESSAGE, DATA, CUSTOM_TYPE, new BaseChannel.SendUserMessageHandler() {
    @Override
    public void onSent(UserMessage userMessage, SendBirdException e) {
        if (e != null) {    // Error.
            return;
        }
    }
});