Start or Join Meeting - Android
After you install VideoSDK, the next step is to integrate VideoSDK features with your app.
To talk with other participants on an audio or video call, you need to join the meeting.
This guide shows how to configure, initialize and join a VideoSDK meeting.

1. Configuration
To configure a meeting, you need a generated token and a meetingId, as described in Server Setup.
This code snippet calls API from local server with OkHttp. Add implementation 'com.squareup.okhttp3:okhttp:4.12.0' to your app's build.gradle; the SDK does not bring it in.
Scenario 1 - If you don't have a meetingId, generate one by calling the create-meeting API.
Scenario 2 - If you have a meetingId, you don't need to call the create-meeting API. Call the validate-meeting API to validate it instead.
Token generation API is necessary for both scenarios.
import android.content.Intent
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
import org.json.JSONException
import org.json.JSONObject
import java.io.IOException
class JoinActivity : AppCompatActivity() {
private val apiServerUrl = "http://localhost:9000"
private val httpClient = OkHttpClient()
// ...
// onCreate() and other methods
// Pass the meetingId you have, or null to create a new meeting
private fun startMeeting(meetingId: String?) {
lifecycleScope.launch {
try {
val token = getToken()
val id = when {
meetingId == null -> createMeeting(token)
validateMeeting(token, meetingId) -> meetingId
else -> return@launch // the meetingId is not valid
}
val intent = Intent(this@JoinActivity, MainActivity::class.java)
intent.putExtra("token", token)
intent.putExtra("meetingId", id)
startActivity(intent)
} catch (e: IOException) {
e.printStackTrace()
} catch (e: JSONException) {
e.printStackTrace()
}
}
}
private suspend fun getToken(): String = withContext(Dispatchers.IO) {
val request = Request.Builder().url("$apiServerUrl/get-token").build()
httpClient.newCall(request).execute().use { response ->
JSONObject(response.body?.string().orEmpty()).getString("token")
}
}
// Scenario 1: create a new meetingId
private suspend fun createMeeting(token: String): String = withContext(Dispatchers.IO) {
val request = Request.Builder()
.url("$apiServerUrl/create-meeting")
.post(FormBody.Builder().add("token", token).build())
.build()
httpClient.newCall(request).execute().use { response ->
JSONObject(response.body?.string().orEmpty()).getString("meetingId")
}
}
// Scenario 2: validate the meetingId you already have
private suspend fun validateMeeting(token: String, meetingId: String): Boolean =
withContext(Dispatchers.IO) {
val request = Request.Builder()
.url("$apiServerUrl/validate-meeting/$meetingId")
.post(FormBody.Builder().add("token", token).build())
.build()
httpClient.newCall(request).execute().use { response -> response.isSuccessful }
}
}
2. Initialization
After configuration, you will have to Initialize
meeting by providing name, meetingId, micEnabled, webcamEnabled & maxResolution.

initMeeting() takes named arguments, and every argument after meetingId has a default value.
import live.videosdk.rtc.android.VideoSDK
import live.videosdk.rtc.android.Meeting
import live.videosdk.rtc.android.lib.VideoSDKException
class MainActivity : AppCompatActivity() {
private lateinit var meeting: Meeting
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Configure parameters
val token = intent.getStringExtra("token") ?: return
val meetingId = intent.getStringExtra("meetingId") ?: return
val participantName = "John Doe"
val micEnabled = true
val webcamEnabled = true
val participantId = "demo@123" // Must be unique per participant. If you pass `null`, the SDK creates an id by itself and uses that id.
val mode = "SEND_AND_RECV"
try {
// Configure authentication token
VideoSDK.config(token)
// create a new meeting instance
meeting = VideoSDK.initMeeting(
context = this@MainActivity,
meetingId = meetingId,
name = participantName,
micEnabled = micEnabled,
webcamEnabled = webcamEnabled,
participantId = participantId,
mode = mode,
)
} catch (e: VideoSDKException) {
// 3073: the token or the meetingId is empty
Log.e("VideoSDK", "initMeeting failed: ${e.code} ${e.name}")
}
}
}
3. Join
After configuration & initialization, the third step is to call join() to join a meeting.
After joining, you will be able to Manage Participant in a meeting.

join() is a suspend function, so call it from a coroutine. It throws VideoSDKException when the meeting can't be joined, for example when the token is invalid or expired.
// Add your MeetingEventListener first, so that no event is missed
meeting.addEventListener(meetingEventListener)
// After receiving mic and webcam access permissions
// join the meeting
lifecycleScope.launch {
try {
meeting.join()
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "Join failed: ${e.code} ${e.name} ${e.message}")
}
}
Events
The following events are emitted on the meeting when it is successfully joined.
- Local Participant will receive an
onMeetingJoinedevent when successfully joined. - Remote Participant will receive an
onParticipantJoinedevent with the newly joinedParticipantobject from the event callback.
Add the listener with meeting.addEventListener() before you call join(), as shown in Join, so that you don't miss onMeetingJoined.
private val meetingEventListener = object : MeetingEventListener() {
override fun onMeetingJoined(switchRoomId: String?) {
Log.d("#meeting", "onMeetingJoined()")
}
override fun onParticipantJoined(participant: Participant) {
Log.d("#meeting", participant.displayName + " joined")
}
}
Got a Question? Ask us on discord

