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 meeting.startWhiteboard()
method, which triggers the onWhiteboardStarted()
event. The event provides the URL to load in the WebView for rendering. To stop it, call meeting.stopWhiteboard()
, which triggers the onWhiteboardStopped()
event.
- Kotlin
- Java
class MeetingActivity : AppCompatActivity() {
private lateinit var meeting: Meeting
private lateinit var webView: WebView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_meeting)
webView = findViewById(R.id.webView)
// Init and config meeting
// meeting = ...
meeting.addEventListener(meetingEventListener);
val meetingEventListener = object : MeetingEventListener() {
override fun onWhiteboardStarted(url: String) {
super.onWhiteboardStarted(url)
webView.loadUrl(url)
webView.settings.javaScriptEnabled = true
webView.webViewClient = WebViewClient()
}
override fun onWhiteboardStopped() {
super.onWhiteboardStopped()
//...
}
}
findViewById<View>(R.id.btnStartWhiteboard).setOnClickListener {
meeting.startWhiteboard()
}
findViewById<View>(R.id.btnStopWhiteboard).setOnClickListener {
meeting.stopWhiteboard()
}
}
}
public class MeetingActivity extends AppCompatActivity {
private Meeting meeting;
private WebView webView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
webView = findViewById(R.id.webView);
/*
init and config meeting ...
meeting = //...
*/
meeting.addEventListener(meetingEventListener);
final MeetingEventListener meetingEventListener = new MeetingEventListener() {
//...
@Override
public void onWhiteboardStarted(String url) {
super.onWhiteboardStarted(url);
webView.loadUrl(url);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
}
@Override
public void onWhiteboardStopped() {
super.onWhiteboardStopped();
//...
}
};
findViewById(R.id.btnStartWhiteboard).setOnClickListener(v -> {
meeting.startWhiteboard();
});
findViewById(R.id.btnStopWhiteboard).setOnClickListener(v -> {
meeting.stopWhiteboard();
});
}
}
API Reference
Got a Question? Ask us on discord