Quickstart
This quickstart shows how to use RealtimeKit's core SDKs to add live video and audio to your Android applications.
To get started quickly, you can use our sample code. You can clone and run a sample application from the Android Core samples, available in both Kotlin and Java.
Objective
You'll learn how to:
- Install the RealtimeKit SDK
- Initialize the SDK
- Configure a RealtimeKit meeting
- Initialize the RealtimeKit meeting
- Go live with your RealtimeKit meeting
Before Getting Started
Make sure you've read the Getting Started with RealtimeKit topic and completed the following steps:
- Create a Developer Account
- Create a RealtimeKit Meeting
- Add Participant to the meeting
- Install Android Studio
Step 1: Install the SDK
dependencies {
// (other dependencies)
implementation 'com.cloudflare.realtimekit:core:+'
}
If your app targets lower versions of Android (Android API <= 24), please enable core desugaring in your app's build.gradle file as follows.
android {
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
}
dependencies {
// other dependencies
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
}
Step 2: Initialize the SDK
The RealtimeKitClient
class is the main entry of the SDK. You can obtain an instance of it using
the RealtimeKitMeetingBuilder
helper as shown below.
- Kotlin
- Java
val rtkClient = RealtimeKitMeetingBuilder.build(activity)
RealtimeKitClient rtkClient = RealtimeKitMeetingBuilder.INSTANCE.build(activity);
Step 3: Configure a RealtimeKit meeting
Configure the following properties in the RtkMeetingInfo
class. You must pass a valid participant authToken
obtained from
the Add Participant API.
Name | Description |
---|---|
authToken | After you've created the meeting, add each participant to the meeting using the Add Participant API The API response contains the authToken . |
enableAudio | Set whether to join the meeting with your Mic ON (true ) or OFF (false ). |
enableVideo | Set whether to join the meeting with your Camera ON (true ) or OFF (false ). |
- Kotlin
- Java
val meetingInfo =
RtkMeetingInfo(
authToken = AUTH_TOKEN,
enableAudio = true,
enableVideo = true,
)
RtkMeetingInfo meetingInfo =
new RtkMeetingInfo(
MeetingConfig.AUTH_TOKEN, // authToken
true, // enableAudio
true, // enableVideo
);
Step 4: Initialize the RealtimeKit meeting
To initialize the meeting, call the init()
method on the rtkClient
object with the meetingInfo
argument. This establishes
a connection with the RealtimeKit meeting server.
- Kotlin
- Java
rtkClient.init(
meetingInfo,
onInitCompleted = {
},
onInitFailed = {
}
)
rtkClient.init(
meetingInfo,
() -> {
// init complete
return null;
},
() -> {
// init failed
return null;
}
);
Step 5: Go live with your RealtimeKit meeting!
Now, you have established the connection with the RealtimeKit meeting server successfully. Next step is to join the room.
Join the room
To join the meeting room, call joinRoom()
method on the rtkClient
instance as shown below.
- Kotlin
- Java
rtkClient.joinRoom(
onSuccess = {
},
onFailed = {
}
)
rtkClient.joinRoom(
() -> {
// join complete
return null;
},
() -> {
// join failed
return null;
}
);
Leave the room
Once the meeting is over, you can leave the meeting room.
To leave the meeting room, call leaveRoom()
method on the rtkClient
as shown below.
- Kotlin
- Java
rtkClient.leaveRoom(
onSuccess = {
},
onFailed = {
}
)
rtkClient.leaveRoom(
() -> {
// leave complete
return null;
}, () -> {
// leave failed
return null;
}
);