> For the complete documentation index, see [llms.txt](https://docs.tryterra.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tryterra.co/streaming-api/your-app-greater-than-terra/android.md).

# Android

Once you've started receiving data from a [device](/reference/streaming-api/core-concepts.md#device) into your app, you can start sending this data to Terra's websocket server (the [broker](/reference/streaming-api/core-concepts.md#broker)).

This will later allow you to receive it on your backend, and process it as per your requirements.

{% hint style="info" %}

#### Prerequisite

Before following the steps below, make sure you've followed the guide to [stream data from a wearable device to your app](/streaming-api/connect-wearable-to-sdk/android.md)
{% endhint %}

## Setting up a connection

You'll have previously set up a stream between a wearable [device](/reference/streaming-api/core-concepts.md#device) and your app [using the startRealtime function](/streaming-api/connect-wearable-to-sdk/android.md#start-real-time-streaming). In order to send this data to the [broker](/reference/streaming-api/core-concepts.md#broker), use the `startRealtime` overload that accepts a `token`:

```kotlin
import co.tryterra.terrartandroid.TerraRT
import co.tryterra.terrartandroid.enums.Connections
import co.tryterra.terrartandroid.enums.DataTypes
import co.tryterra.terrartandroid.models.Update

// Assumes terraRT is already initialized and a device is connected
// (see the "Connect Wearable to SDK" guide)

val token = "yourStreamingToken"  // Generated from your backend (see below)
val dataTypes = setOf(DataTypes.HEART_RATE, DataTypes.STEPS)

// Stream to BOTH your app AND Terra's websocket server
terraRT.startRealtime(
    type = Connections.BLE,
    dataTypes = dataTypes,
    token = token,
    updateHandler = { update ->
        println("${update.type}: ${update.`val`} at ${update.ts}")
    },
    connectionCallback = { connected ->
        println("Websocket connected: $connected")
    }
)
```

Simply passing in a token from the following endpoint will allow you to stream the same data you were reading previously within your app, and have it sent to the broker.

{% hint style="info" %}
Make sure to pass in the correct user ID in the `id` query parameter in the call below. You may retrieve that user ID using the [`getUserId`](/reference/streaming-api/reference/android-kotlin.md#getuserid) function in the SDK.
{% endhint %}

{% openapi src="<https://raw.githubusercontent.com/tryterra/openapi/refs/heads/master/dist/rt-bundled.yaml>" path="/auth/user" method="post" %}
<https://raw.githubusercontent.com/tryterra/openapi/refs/heads/master/dist/rt-bundled.yaml>
{% endopenapi %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tryterra.co/streaming-api/your-app-greater-than-terra/android.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
