Skip to main content
Version: 3.x.x

Render Whiteboard - Android

This guide explains how to dynamically render a whiteboard in your Android application.

Setup WebView​

  • The whiteboard is rendered using a WebView component.
  • You can configure the required XML style using the following code
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

Render the Whiteboard​

You can start the whiteboard with room.startWhiteboard() method, which triggers the onWhiteboardStarted() event. The event provides the URL to load in the WebView for rendering. To stop it, call room.stopWhiteboard(), which triggers the onWhiteboardStopped() event.

Both methods are suspend functions, so call them from a coroutine. They throw a VideoSDKException if the request fails.

class RoomActivity : AppCompatActivity() {

private lateinit var room: Room
private lateinit var webView: WebView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_room)

webView = findViewById(R.id.webView)

// Create the room
// room = VideoSDK.createRoom(...)

val roomEventListener = object : RoomEventListener() {
override fun onWhiteboardStarted(url: String) {
super.onWhiteboardStarted(url)
webView.settings.javaScriptEnabled = true
webView.webViewClient = WebViewClient()
webView.loadUrl(url)
}

override fun onWhiteboardStopped() {
super.onWhiteboardStopped()
//...
}
}

room.addEventListener(roomEventListener)

findViewById<View>(R.id.btnStartWhiteboard).setOnClickListener {
lifecycleScope.launch {
try {
room.startWhiteboard()
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "startWhiteboard failed: ${e.code} ${e.message}")
}
}
}

findViewById<View>(R.id.btnStopWhiteboard).setOnClickListener {
lifecycleScope.launch {
try {
room.stopWhiteboard()
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "stopWhiteboard failed: ${e.code} ${e.message}")
}
}
}
}
}

API Reference​

Got a Question? Ask us on discord