The Android SDK wraps the Messaging API. All WebSocket events, streaming, and handoff behavior documented in the API reference apply.
Source on GitHub
polyai/android-sdk — Kotlin library, Maven Central, and example apps.
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.1
Install the SDK
Add the SDK to your project via Maven Central.
2
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.3
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.4
Build your UI
Observe
ChatSession state via Kotlin StateFlow — collect messages, connection status, typing indicators, and more. Render the conversation in your own UI components.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
No permissions to declare — the SDK’s manifest merges
INTERNET and ACCESS_NETWORK_STATE into your app automatically. R8/minify works without extra configuration.
Authentication setup
The Android SDK authenticates using a connector token and your app’s package name.1
Generate a connector token
In Agent Studio, go to Messaging > API Configuration and generate a new Messaging API key.
2
Register your package name
Your app’s
applicationId is sent as the X-Host header. It must match the host registered in Agent Studio for your 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
Environments
ChatSession reference
State (read-only StateFlow properties)
Methods
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.
Limitations
These limitations apply to the initial release. Check the release notes for updates.
Example apps
The SDK ships with a 7-rung example ladder, mirrored across Jetpack Compose and Android Views:
Browse the examples on GitHub.
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

