androidAndroid (Kotlin)

Connections

enum class Connections {
    BLE,          // Bluetooth Low Energy devices (heart rate monitors, etc.)
    WEAR_OS,      // Wear OS watches via classic Bluetooth
    ANDROID,      // Phone's built-in sensors (accelerometer, gyroscope)
    ANT,          // ANT+ protocol devices
    ALL_DEVICES,  // Combined BLE + ANT scanning/connection
}

DataTypes

enum class DataTypes {
    HEART_RATE, ECG, STEPS, HRV, CALORIES, LOCATION, DISTANCE,
    ACTIVITY, ACCELERATION, GYROSCOPE, FLOORS_CLIMBED, STEPS_CADENCE,
    SPEED, POWER, BIKE_CADENCE, MET, RR_INTERVAL,
    CORE_TEMPERATURE, SKIN_TEMPERATURE
}

Update

Data points delivered via streaming callbacks.

For scalar metrics (heart rate, steps), the value is in val. For vector metrics (acceleration, gyroscope), the values are in d. Note: val is a Kotlin reserved keyword — access it with backticks: update.`val`.

Device

Represents a discovered BLE/ANT device.

ConnectedDevice

Represents a currently connected device.

ConnectionState


Initialization

TerraRT

Creates and authenticates a TerraRT instance. Makes a network call to Terra's servers. Requests required Android permissions (Bluetooth, location, activity recognition, body sensors) if not already granted.

  • devId ➡ Your developer ID from the Terra Dashboardarrow-up-right.

  • context ➡ Activity context (required for permission dialogs).

  • referenceId ➡ Optional user identifier in your system. Appears as reference_id in webhooks.

  • completiontrue if initialization succeeded.

Connection Setup

initConnection

Authenticates the SDK user with Terra's backend. Makes a network call. The token should be generated server-side via the Generate Authentication Tokenarrow-up-right endpoint.

getUserId

Returns the Terra user ID, or null if not yet initialized. Synchronous, no network call.

disconnect

Disconnects from the given connection type.

Device Scanning

Two overloads for different scanning workflows:

startDeviceScan (with device callback)

Starts scanning and calls deviceCallback for each discovered device. You then call connectDevice() to connect to a chosen device.

startDeviceScan (with built-in UI)

Starts scanning with automatic connection handling. If useCache is true, reconnects to a previously paired device. If not found and showWidgetIfCacheNotFound is true, shows the built-in device picker UI.

connectDevice

Connects to a specific Device returned from the device-callback startDeviceScan overload.

getConnectedDevices

Returns the set of currently connected devices.

Data Streaming

Three startRealtime overloads for different streaming modes:

startRealtime (server + local)

Streams data to both Terra's websocket server and a local updateHandler callback.

startRealtime (local only)

Streams data to a local callback only. No server connection.

startRealtime (server only)

Streams data to Terra's websocket server only. No local callback.

circle-exclamation

Parameters:

  • type ➡ The connection type.

  • dataTypes ➡ Set of data types to stream. Defaults to empty (streams all available).

  • token ➡ Authentication token for the websocket connection.

  • updateHandler ➡ Called with each Update data point.

  • connectionCallback ➡ Called when the websocket connection state changes.

stopRealtime

Stops streaming for a given connection type.

Static Methods

setWebsocketEventListener

Sets a global listener for websocket connection events.

Last updated

Was this helpful?