Skip to main content
The Android SDK is a native Kotlin library that embeds PolyAI’s messaging agent directly inside your Android app. It’s headless by design — you own the UI, PolyAI provides the AI layer underneath. Your app connects to the same agent logic used across voice, webchat, and other channels. As of v0.9.0 it covers two channels, chat (ai.poly:messaging) and live two-way voice calls (ai.poly:voice).
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. Voice calling ships as a separate artifact, ai.poly:voice, so chat-only apps stay lean. It reuses the same configuration and vocabulary as messaging, so there are no new concepts to learn if you already run chat. See Voice calling (Android) for the full guide.
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 as ai.poly:messaging. Ensure mavenCentral() is in your repositories (it’s there by default in new Android projects).

Requirements

No permissions to declare — the SDK’s manifest merges INTERNET and ACCESS_NETWORK_STATE into your app automatically. (Voice calls need RECORD_AUDIO — see Voice calling permissions.)

Authentication setup

The Android SDK authenticates using a connector token and your app’s package name. Voice calling needs one further credential from the same page, the WebRTC token, a distinct value that authenticates the media connection. Both tokens come from the same connector you use for chat. See Voice calling credentials.
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 in Application.onCreate(), then create a ChatSession and render messages.

Initialize once

Register it in your manifest with android:name=".HelloApplication". No network happens at init — the work starts when you call chat().

Build the chat UI

Key features

Session persistence

Conversations survive an app relaunch. PolyMessaging.chat() resumes the stored session automatically if it’s still valid, or starts a fresh one — you don’t need to check anything first. Sessions can only be resumed within the session timeout of ~10 minutes (matching the backend’s WebSocket idle timeout); after that, chat() starts a new conversation. Use PolyMessaging.start() when you want to always begin fresh (an explicit “New chat” entry point), and PolyMessaging.hasResumableSession() when you want to offer the user the choice before showing the chat:

Streaming responses

Streaming is on by default — agent replies grow token-by-token. The SDK reassembles chunks and updates session.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 via ChatMessage.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 include suggestions — 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 the attachments field — images (AttachmentContentType.IMAGE), link cards (AttachmentContentType.URL), and call-to-action phone buttons (callActions).

Delivery tracking

User messages appear immediately as Delivery.PENDING, then settle to SENT or FAILED. The SDK never auto-resends — one send is one send, so a message can’t be delivered twice. An unconfirmed message is marked FAILED as soon as it can’t be confirmed: immediately if it was sent while offline, at the moment the connection drops if it was still in flight, or after a 10-second wait if the server never echoes it back. Your UI must offer its own retry affordance — it isn’t a backstop for SDK retries, it’s the only way a failed message gets sent. On FAILED, call removeMessage(draftId) then re-send the text.

Connection & reconnect

The SDK reconnects automatically with exponential backoff and jitter. Reconnection applies to the socket only — failed messages are never resent automatically (see Delivery tracking above). Observe session.connection to show a reconnect banner:
When the reconnect budget is exhausted (ConnectionStatus.Failed), recover with session.client.startNewSession().

Voice calling

ai.poly:voice places live, two-way WebRTC voice calls to the same agent that powers your chat. Calls are user-initiated: the user taps to call your agent.
A call needs two credentials (the API key plus a separate WebRTC token, both from Agent Studio › Connector Settings) and the RECORD_AUDIO runtime permission granted before starting; the SDK’s manifest declares everything else a basic call needs. Beyond that the SDK handles the hard parts for you: accessory-aware audio routing, automatic reconnection on transient network drops, and graceful handling of interruptions like incoming phone calls.

Voice calling (Android)

The full voice guide: installation, credentials, permissions, audio output, interruptions, background calls, and R8.

Configuration reference

The same environment also selects the gateway for voice calls. The full configuration reference on GitHub covers the remaining options, error handling and connection states.

Environments

ChatSession reference

State (read-only StateFlow properties)

Methods

Platform values

When the SDK creates a session, it sets platform to android automatically, alongside a device_type (mobile / tablet). This is visible in Agent Studio analytics and can be used in your agent logic to tailor behavior for mobile users. It identifies the device, not the channel — for the channel a conversation arrives on, see Multichannel below.

Limitations

These limitations apply to the initial release. Check the release notes for updates.

Example apps

The android-sdk repository ships runnable example apps for both chat and voice, each mirrored across Compose and Views: a full chat implementation with streaming, suggestions and handoff, and a one-screen tap-to-call demo with the audio-output picker. With a 7 rung example ladder: 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. Two values tell your agent where a conversation came from, and they answer different questions:
  • conv.channel_type identifies the channel. Its possible values are webchat.polyai, chat.polyai, sms.twilio, sms.polyai, rcs.polyai, whatsapp.polyai, and sip.polyai — it is never "android" or "ios".
  • platform identifies the device: the SDK sends platform: "android" (alongside device_type) when the session is created. Use this to tailor behavior for native app users.
To branch on the channel in your agent’s start function:

Voice calling (Android)

WebRTC voice calls with ai.poly:voice: setup, permissions, audio output, and background calls

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
Last modified on August 13, 2026