Pairing

Pair a native Android app with Ansight Studio through developer pairing, saved configs, explicit payloads, or the Android pairing sheet.

Runtime-owned host connection APIs live on AnsightRuntime.

Auto-Connect

import ai.ansight.runtime.AnsightRuntime
import ai.ansight.runtime.HostConnectionRequest

val result = AnsightRuntime.connect(
    HostConnectionRequest.auto(clientName = "Android App")
)

if (!result.success) {
    Log.w("Ansight", result.message)
}

Automatic connection tries bundled developer config, remembered host profiles, saved pairing config, and bundled config.

Host auto-probe is enabled by default while the runtime is active. It remembers previous host connections and retries them so the app can reconnect after the host disappears and later reappears. Probing pauses while a live session is connected and resumes after the retry delay when that session is lost:

val options = AnsightOptions.createBuilder()
    .withHostAutoProbe(
        AnsightHostAutoProbeOptions(
            enabled = true,
            initialDelayMilliseconds = 1_000,
            probeIntervalMilliseconds = 5_000,
            reconnectDelayMilliseconds = 10_000,
            clientName = "Android App",
        ),
    )
    .build()

Use withoutHostAutoProbe() for flows where reconnects should only happen after an explicit app action.

Explicit Payload

AnsightRuntime.connect(
    HostConnectionRequest.payloadText(
        payload = pairingJson,
        clientName = "Android App",
        expectedAppId = application.packageName,
    ),
)

Saved Pairing

AnsightRuntime.savePairingConfig(pairingJson, expectedAppId = application.packageName)
AnsightRuntime.clearSavedPairingConfig()
AnsightRuntime.clearCachedSession()
AnsightRuntime.disconnect()

Saved pairing config is stored in Android SharedPreferences under the configured host connection key.

Pairing Sheet

The all-in-one package exposes the native Android pairing sheet. It lets the developer scan a QR code or paste a pairing payload, then calls AnsightRuntime.connect(...) for the app.

import ai.ansight.Ansight

Ansight.showPairingSheet(
    activity = activity,
    clientName = "Android App",
    expectedAppId = activity.packageName,
    onResult = { result ->
        Log.d("Ansight", result.message)
    },
    onError = { error ->
        Log.e("Ansight", "Pairing failed", error)
    },
)

The same QR flow is also available without the sheet:

import ai.ansight.runtime.AnsightRuntime
import ai.ansight.runtime.HostConnectionRequest

val result = AnsightRuntime.connect(
    HostConnectionRequest.qrCode(
        clientName = "Android App",
        expectedAppId = activity.packageName,
    ),
)

Keep developer pairing payloads out of distributable builds.