Communication

This guide explains how to establish seamless bidirectional communication between your Android app and the LiSA Player running within a WebView. By leveraging native-to-JavaScript bridges and WebView event listeners, you can enable your Android app and the LiSA Player to exchange data, trigger events, and synchronize state in real time.

Whether you need to send commands from you app to the LiSA Player (e.g., changing app behavior or updating content) or pass data from the WebView back to your app (e.g., user actions or analytics), this guide will walk you through the necessary setup and best practices for efficient, secure, and reliable communication.

Receiving Messages

To receive messages from the LiSA Player In your Android app, use addJavascriptInterface:

// Add JavaScript interface to handle messages from the web app
webView.addJavascriptInterface(WebAppInterface(), "MessageFromLiSA")
private class WebAppInterface {
    @android.webkit.JavascriptInterface
    fun postMessage(message: String) {
        println("Message received from LiSA: $message")
        // Process the JSON message here
    }
}
  • The WebAppInterface is registered under the name MessageFromLiSA.

  • When the LiSA Player sends a message using window.MessageFromLiSA.postMessage, the postMessage function in the interface processes it.

  • You can handle the JSON message inside the postMessage method.


Sending messages

Use the evaluateJavascript method in Kotlin to send a message to the web app:

webView.evaluateJavascript("""
    window.postMessage(JSON.stringify({ type: 'event', payload: { key: 'value' } }));
""", null)

Last updated