Live SDKs Android v1
Live SDKs Android
Live SDKs
Android
Version 1

Start your first live

Copy link

Sendbird Live SDK for Android offers a variety of functionalities for hosting and watching live events. As a live event's host, a user can create, share their media stream, and use the chat to communicate with other users watching the live event. Users can enter a live event as participants to watch the live event and use the chat to communicate with the live event's host as well as other users.


Requirements

Copy link

The minimum requirements for the Live SDK for Android are:

  • Android 5.0 (API level 21) or later
  • Java 8 or higher
  • Support androidx only
  • Android Gradle plugin 4.0.1 or higher
  • Sendbird Chat SDK for Android 4.12.0 or higher

Before you start

Copy link

Sendbird Live SDK provides live streaming feature and uses open channels from Sendbird Chat SDK for chat. Installing Sendbird Live SDK will automatically install the Chat SDK as well.

Before installing the Live SDK, create a Sendbird account to acquire an application ID which you will need to initialize the Live SDK. Go to Sendbird Dashboard and create an application by selecting Calls+Live in product type. Once you've created an application, go to Overview and you will see the Application ID.


Get started

Copy link

You can start building your a live event by installing the Live SDK first.

Step 1 Create a project

Copy link

To get started, open Android Studio and create a new project for the Live 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. Make sure Use legacy android.support.libraries is unchecked.

  6. Select minimum API level as 21 or higher.


Step 2 Install the Live SDK

Copy link

You can install the Live UIKit for Android through Gradle. If you're using Gradle 6.7 or lower, add the following code to your root build.gradle file.

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        maven { url "https://repo.sendbird.com/public/maven" }
    }
}

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

If using Gradle 6.8 or higher, add the following to your settings.gradle file.

dependencyResolutionManagement {
    repositories {
        maven { url "https://jitpack.io" }
        maven { url "https://repo.sendbird.com/public/maven" }
    }
}

Note: To learn more about updates to Gradle, visit this page.

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.

android {
    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:sendbird-live:1.2.7'
}

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

Step 3 Request permission to access camera and microphone

Copy link

Your users need to grant the client app the permission to access camera and microphone to stream media. They also need to allow access to the photo library to send and download images and videos.

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <!--  To detect bluetooth audio device  -->
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

    <!--  To utilize audio in livestreaming event  -->
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />

    <!--  To utilize video in livestreaming event for audio  -->
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.AUDIO_SESSION_ID_GENERATE" />

    ...
</manifest>

Step 3-2 (Optional) Configure ProGuard to shrink code and resources

Copy link

When you build your APK with minifyEnabled set to true, add the following line to the module's ProGuard rules file to ensure the SDK's proper functioning.

# Sendbird Live SDK
-keep class com.sendbird.live.** { *; }

Step 4 Initialize the SendbirdLiveSDK instance

Copy link

To integrate the Live SDK in the client app, you need to initialize it first. But, prior to initializing the Live SDK, you must initialize Sendbird Chat SDK first. Refer to the following documentation to understand how to initialize Sendbird Chat SDK.

After initializing Sendbird Chat SDK, initialize the SendbirdLive instance using the SendbirdLive.init() method. Initialization requires your Sendbird application's Application ID, which can be found on the Sendbird Dashboard.

val params = InitParams(APP_ID, applicationContext)
SendbirdLive.init(params, object : InitResultHandler {
    override fun onInitFailed(e: SendbirdException) {
       ...
    }

    override fun onInitSucceed() {
       ...
    }

    override fun onMigrationStarted() {
       ...
    }
})

Note: The SendbirdLive.init() method must be called across the client app at least once. It is recommended to initialize the Live SDK with the onCreate() method of the Application instance.

Step 5 Authenticate a user

Copy link

To start or enter a live streaming, you need to authenticate a user with the Sendbird server using their user ID through the authenticate() method.

val params = AuthenticateParams(userId, accessToken)
SendbirdLive.authenticate(params) { user, e ->
   if (e != null) {
       //handle error
       return@authenticate
   }
   // The user has been authenticated successfully and is connected to Sendbird server.
}

Authenticating a user with the Live SDK will also authenticate the user in the Chat SDK if you haven't authenticated the user in the Chat SDK yet. After authenticating the user, you can start broadcast or watch live events.

Step 6 Create a live event

Copy link

To start a live event, you need to create one first. A live event can be created using the SendbirdLive.createLiveEvent() method, and you can configure information about the live event through the LiveEventCreateParams instance.

val params = LiveEventCreateParams(userIdsForHost).apply {
   title = TITLE
   coverUrl = COVER_URL
   customItems = CUSTOM_ITEMS
   reactionKeys = REACTION_KEYS
}
SendbirdLive.createLiveEvent(params) { liveEvent, e ->
   if (e != null) {
       //handle error
       return@createLiveEvent
   }
}

Step 7 Start your first live

Copy link

When a live event is created, you can choose to enter as a host or a participant.

liveEvent.enterAsHost(MediaOptions(videoDevice = VIDEO_DEVICE, audioDevice = AUDIO_DEVICE.value)) {
    if (it != null) {
        return@enterAsHost
    }
}

If you've entered as a host, you can start the live event by making the following call.

liveEvent.startEvent {
   if (it != null) {
       // handle error
       return@startEvent
   }
   // The live event has started. Participants can now view the host's video.
}

Step 8 Watch your first live

Copy link

when a host and participants enter the live event, you can stream the first live event for participants to watch with Sendbird Live. The host and participants also can actively engage in the live event by chatting with each other.

liveEvent.enter() {
    if (it != null) {
        return@enter
    }
}