Adding Decagon to your Android App
There are plenty of resources online about adding a WebView to Android so this guide will focus primarily on what to put in your WebView!
Step 1: Add the Webview to your Layout
Go to your app's layout file (e.g., activity_main.xml
) in the res/layout
folder. Then, add the WebView Widget. For example:
Step 2: Configure your Activity
Open the Java/Kotlin Activity File: For example, MainActivity.java
or MainActivity.kt
Then, initialize WebView:
Java:
In Kotlin:
Finally, point the Webview to your unique URL that contains your mobile chat AI
Step 3: Pass in Metadata
You may pass in arbitrary, unique information about the user as metadata by adding URL params to the URL. This metadata will be saved along with each conversation. User ID is what unique identifies a user and allows conversation history to be saved across sessions. For example:
That's it! You may find more in-depth guides on adding WebViews in Android on the internet if you need further assistance.
Step 4: (Optional) Pass in user token
If a token needs to used by the AI to uniquely and securely identify a user (e.g. to use for API calls), we recommend passing it in via the X-DECAGON-USER-TOKEN
URL header in your WebView, and not as an URL param. This token will be passed to the Decagon backend on every chat message to be used in AI workflows.
Create a Map<String, String>
(i.e. a headers map) that will hold your custom headers. For example:
Then, include the headers map when loading your WebView.
See here for more info.
Last updated