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, 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.
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.
You can start building a 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.
Next, for all Gradle versions, open the build.gradle file at the application level. For both Java and Kotlin, add the following code block and dependencies:
apply plugin: 'com.android.application'
android {
buildFeatures {
viewBinding 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:3.+'
}
Before saving the build.gradle file, check if you’ve enabled viewBinding. 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.
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.
Note: Local caching has now been added so that the client app can locally cache and retrieve channel and message data. The addition of this functionality requires the database to be reset and migrated. As a result of DB migration in the server, the initialization process of the SendbirdUIKit instance is now asynchronous and requires you to receive a callback function before you can move onto the next step. If the database fails to migrate, the onInitFailed() method is called. If the database successfully migrates, the onInitSucceed() method is called and you can proceed to the next step. Refer to the updated code below.
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.sendbird.uikit.SendbirdUIKit;
import com.sendbird.uikit.adapter.SendbirdUIKitAdapter;
import com.sendbird.uikit.interfaces.UserInfo;
import com.sendbird.android.handler.InitResultHandler;
import com.sendbird.android.exception.SendbirdException;
public class BaseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
SendbirdUIKit.init(new SendbirdUIKitAdapter() {
@NonNull
@Override
public String getAppId() {
return "YOUR_APP_ID"; // Specify your Sendbird application ID.
}
@Nullable
@Override
public String getAccessToken() {
return "";
}
@NonNull
@Override
public UserInfo getUserInfo() {
return new UserInfo() {
@Override
public String getUserId() {
return "USER_ID"; // Specify your user ID.
}
@Nullable
@Override
public String getNickname() {
return "USER_NICKNAME"; // Specify your user nickname.
}
@Nullable
@Override
public String getProfileUrl() {
return "";
}
};
}
@NonNull
@Override
public InitResultHandler getInitResultHandler() {
return new InitResultHandler() {
@Override
public void onMigrationStarted() {
// DB migration has started.
}
@Override
public void onInitFailed(SendbirdException e) {
// If DB migration fails, this method is called.
}
@Override
public void onInitSucceed() {
// If DB migration is successful, this method is called and you can proceed to the next step.
// In the sample app, the `LiveData` class notifies you on the initialization progress
// And observes the `MutableLiveData<InitState> initState` value in `SplashActivity()`.
// If successful, the `LoginActivity` screen
// Or the `HomeActivity` screen will show.
}
};
}
}, this);
}
}
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.
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.
}
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.