# 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`:

```kotlin
// Add JavaScript interface to handle messages from the web app
webView.addJavascriptInterface(WebAppInterface(), "MessageFromLiSA")
```

```kotlin
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:

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hello-lisa.com/developers/guides/integration-guide/app-integration/android/communication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
