The Android SDK uses the Messaging API under the hood. All WebSocket events, streaming, and handoff behavior documented in the API reference apply.
How it works
The SDK handles authentication, session management, WebSocket connections, and reconnection logic. Your app sends and receives messages through the SDK and renders them however you choose — in Jetpack Compose or Android Views.Configure authentication
Add your API key (from Agent Studio) and ensure your app’s package name (
applicationId) matches the host registered in Agent Studio for your API key.Initialize and start a session
Initialize the SDK once in
Application.onCreate(), then call PolyMessaging.chat() to get a ChatSession. The SDK handles access token exchange and WebSocket connection automatically.Installation
The SDK is published to Maven Central asai.poly:messaging. Ensure mavenCentral() is in your repositories (it’s there by default in new Android projects).
- Kotlin DSL (recommended)
- Groovy DSL
- Version catalog
Requirements
| Requirement | Minimum |
|---|---|
| Android | API 24 (Android 7.0) |
| compileSdk | 36 |
| Kotlin | 2.2+ |
| JDK (to build) | 17 |
| Java consumers | Supported |
INTERNET and ACCESS_NETWORK_STATE into your app automatically. R8/minify works out of the box.
Authentication setup
The Android SDK authenticates using a connector token and your app’s package name.Generate a connector token
In Agent Studio, go to Messaging > API Configuration and generate a new Messaging API key.
Quick start
Initialize the SDK once inApplication.onCreate(), then create a ChatSession and render messages.
Initialize once
android:name=".HelloApplication". No network happens at init — the work starts when you call chat().
Build the chat UI
- Jetpack Compose
- Android Views (XML)
Key features
Session persistence
Sessions persist across app launches. If the user leaves and returns, the SDK reconnects to the existing session and replays the conversation history automatically. UsePolyMessaging.chat() to resume or PolyMessaging.start() to always start fresh.
Streaming responses
Streaming is on by default — agent replies grow token-by-token. The SDK reassembles chunks and updatessession.messages automatically. To switch to complete-message bubbles, set streamingEnabled = false on the Configuration.
Handoff to live agents
The full handoff flow is supported. When the PolyAI agent triggers a handoff, the SDK delivers the same handoff events viaChatMessage.System messages with typed SystemEvent cases (HandoffStarted, QueueStatus, LiveAgentJoined, etc.). Live agent messages arrive as ChatMessage.Agent with agentKind == AgentKind.LIVE.
Response suggestions
Agent messages can includesuggestions — pre-written reply options. Render these as tappable chips in your UI. When the user taps one, call clearSuggestions(messageId) then send(suggestion.messageText).
Attachments
Agent messages may include rich content via theattachments field — images (AttachmentContentType.IMAGE), link cards (AttachmentContentType.URL), and call-to-action phone buttons (callActions).
Delivery tracking
User messages appear immediately asDelivery.PENDING, then settle to SENT or FAILED. The SDK retries automatically (every 3s, up to 3 times). On FAILED, call removeMessage(draftId) then re-send.
Connection & reconnect
The SDK reconnects automatically with exponential backoff and jitter. Observesession.connection to show a reconnect banner:
ConnectionStatus.Failed), recover with session.client.startNewSession().
Configuration reference
| Field | Default | Description |
|---|---|---|
apiKey | — (required) | API key from Agent Studio |
environment | Environment.US | US / UK / EUW / cluster("name") / custom(restUrl, wsUrl) |
hostIdentifier | package name | X-Host for connector validation |
streamingEnabled | true | Token-by-token (true) or complete bubbles (false) |
logLevel | LogLevel.ERROR | NONE / ERROR / WARN / INFO / DEBUG |
maxReconnectAttempts | 10 | Reconnect budget before Failed |
Environments
| Environment | Endpoint |
|---|---|
Environment.US (default) | messaging.us-1.poly.ai |
Environment.UK | messaging.uk-1.poly.ai |
Environment.EUW | messaging.euw-1.poly.ai |
Environment.cluster("name") | messaging.<name>.poly.ai |
ChatSession reference
State (read-only StateFlow properties)
| Property | Type | Description |
|---|---|---|
messages | StateFlow<List<ChatMessage>> | Full transcript — ChatMessage.User / .Agent / .System |
isReady | StateFlow<Boolean> | Connected and ready to send |
connection | StateFlow<ConnectionStatus> | Socket state |
isAgentTyping | StateFlow<Boolean> | Show typing indicator |
agentAvatarUrl | StateFlow<URI?> | Latest agent avatar |
hasEnded | StateFlow<Boolean> | Conversation is over |
failureReason | StateFlow<PolyError?> | Terminal failure (invalid key, reconnect exhausted, session expired) |
Methods
| Method | Description |
|---|---|
suspend send(text) | Send a user message (optimistic) |
suspend sendTyping() | Broadcast typing (throttled internally) |
suspend end() | End the conversation |
removeMessage(draftId) | Drop a failed draft before re-sending |
clearSuggestions(messageId) | Clear quick-reply pills for a message |
clearChat() | Wipe the transcript |
close() | Tear down this session’s observers |
Platform values
When the SDK creates a session, it setsplatform to android automatically. This is visible in Agent Studio analytics and can be used in your agent logic to tailor behavior for mobile users.
| Platform value | Source |
|---|---|
android | Android SDK (native) |
ios | iOS SDK (native) |
ios-web | Webchat widget on iOS Safari |
web | Webchat widget on desktop |
Limitations
These limitations apply to the initial release. Check the release notes for updates.
| Limitation | Details |
|---|---|
| Text only | Voice input is not supported in V1. WebRTC voice support is planned for a future release. |
| No push notifications | While the app is active, the SDK delivers messages in real time. When the app is killed by the system, no messages arrive. Local notifications work as a workaround while the process is alive. Remote push (FCM) is not yet supported. |
| No React Native or Flutter | The SDK is native Kotlin (Java-compatible). Cross-platform frameworks would require a separate SDK. |
Example apps
The SDK ships with a 7-rung example ladder, mirrored across Jetpack Compose and Android Views:| Level | What it adds |
|---|---|
| 01 Hello | Initialize, render, send |
| 02 Standard | Typing, suggestions, delivery, reconnect, end + start-new |
| 03 Rich Content | Attachments, link cards, tel: actions, Markdown |
| 04 Resilience | Offline banner, loading skeleton, terminal error + retry |
| 05 Handoff | Full live-agent ladder |
| 06 Full Reference | Production resume + start-new flows |
| 07 Playground | Diagnostics, runtime config, streaming toggle |
Multichannel
The Android SDK connects to the same agent project as your voice and webchat channels. Agent behavior, knowledge, and flows are shared — only channel-specific settings (greetings, formatting) differ. See multichannel agents for how to tailor behavior per channel. In your agent’s start function, detect the mobile channel usingconv.channel_type:
Related pages
Messaging API reference
Full WebSocket protocol, events, streaming, and handoff
Sessions and authentication
Access tokens, session creation, and platform values
Multichannel agents
Build agents that work across voice, webchat, and mobile
Best practices
Connection management, UX, and security recommendations

