Mobile apps (WebView)
Embed the Symptom & Illness Check App in a native app with a WebView.
To use the Symptom & Illness Check App in a native app, load a page that embeds it with the JS API into a WebView. Enable JavaScript and DOM storage in the WebView.
The examples on this page use await; run them inside an async function or a <script type="module">.
Auth code from your backend
Your app requests a fresh authCode from your own backend every time it opens the WebView. Never create the auth code inside your app: it would need the API key, and anyone can extract it from your app — see Keep the API key on your server.
suspend fun getAuthCode(): String = withContext(Dispatchers.IO) {
val response = URL("https://your-backend.example.com/xund-auth").readText() // your own backend endpoint, not part of the XUND API
JSONObject(response).getString("authCode")
}Passing the report to native code
Register a JavaScript interface in the WebView and call it from onReportShown:
const xundApp = await XUND.scic.init({
clientId: 'YOUR-CLIENT-ID',
webappCode: 'YOUR-WEBAPP-CODE',
authCode: 'AUTH-CODE-FROM-YOUR-BACKEND',
targetContainerId: 'xund-container',
customization: {
onReportShown: ({ reportData }) => {
AndroidXund.onReportShown(JSON.stringify(reportData)) // your app's JavaScript interface, not part of the XUND API
},
},
})Here AndroidXund is the name under which the app registered its @JavascriptInterface object.
A complete Android project is in the Android WebView example on GitHub. Note that the example creates the auth code inside the app to stay self-contained; move that step to your backend before you ship.
Last updated on