Skip to main content

Overview

This guide walks you through the complete integration of the Open Wearables Android SDK into a native Kotlin application, from backend setup to production deployment.
1

Set up backend authentication endpoint

2

Initialize and configure the SDK

3

Implement sign-in flow

4

Select health provider

5

Request health permissions

6

Start background sync

Authentication Architecture

The SDK supports two authentication modes: token-based (recommended) and API key. The token-based flow keeps your App credentials safe on your backend:

Your Backend generates token

Your backend calls the Open Wearables API with your App credentials (app_id + app_secret) to generate a user-scoped token (server-to-server, HTTPS) via Create User Token endpoint. Open Wearables returns access_token + refresh_token.

Your Backend returns tokens to the app

Your backend exposes its own custom endpoint that forwards the access_token and refresh_token to the mobile app. Never expose app_id or app_secret to the client.

Mobile App calls SDK signIn

The Android app receives the tokens and passes them to sdk.signIn(accessToken, refreshToken).

SDK stores & syncs

Android SDK stores credentials in EncryptedSharedPreferences and uses accessToken to sync health data directly to Open Wearables.
Never embed your app_id / app_secret in the mobile app. App credentials should only exist on your backend server. Only the access_token and refresh_token are passed to the mobile app.
Building a standalone app with no backend of your own? Invitation codes are an alternative - a single-use code the app redeems directly, no backend channel required. This is not the standard flow; it exists mainly for the Open Wearables app and the example apps. If your app authenticates users against your own backend (the normal case), use the backend token flow above. See Choosing an onboarding flow.

Step 1: Backend Setup

Your backend needs a single endpoint that generates access tokens for your users by calling the Open Wearables API and forwarding the tokens.

Generate Access Token

When a user wants to connect their health data, your backend should:
  1. Authenticate the user (your own auth system)
  2. Call Open Wearables API at POST /api/v1/users/{user_id}/token with your App credentials
  3. Return the access_token and refresh_token to the mobile app
The user_id in the URL is the Open Wearables User ID (UUID). You should store this mapping in your database when you first Create User via the Open Wearables API.

Step 2: SDK Initialization & Configuration

Initialize the SDK once in your Application class or main activity, then configure it with your backend host.

Configuration Options

Provide only the base host URL, e.g. https://your-domain.com. Do not append /api/v1/ or any other path — the SDK adds the required path prefix automatically.

Session Restoration

The SDK automatically restores credentials from EncryptedSharedPreferences:

Step 3: Sign In

After getting credentials from your backend, sign in with the SDK.
The userId parameter is the Open Wearables User ID (UUID) — the id returned by the Create User endpoint. Do not pass your own external_user_id here.

API Key Authentication

For simpler setups (e.g. internal tools):
API key authentication embeds the key in the app. Only use this for internal or trusted applications. For production apps, always use token-based authentication.

Automatic Token Refresh

When you provide a refreshToken, the SDK automatically handles 401 responses by refreshing the access token and retrying the request. You can also update tokens manually:

Step 4: Select Health Provider

Before requesting permissions, you must select a health data provider:
Call setProvider() before requestAuthorization(). The SDK needs to know which provider to request permissions from.

Provider Comparison

Health Connect is recommended as the default provider for the widest device and data type support.

Samsung Health SDK dependency

If you target Samsung Health, add Samsung’s own Health Data SDK (distributed as an .aar) to your app module. This is required to use the "samsung" provider at all - including in Developer Mode - not just for production. Download it from the Samsung Health Data SDK page:
Shipping Samsung Health to production requires Samsung’s approval. The permission flow is blocked at runtime until Samsung approves your partnership request and allowlists your release signing key. See Samsung Health Production Requirements before you plan a release.
Testing Samsung Health: Samsung Health is not available in the Android emulator - test on a physical Samsung device with the Samsung Health app installed. Before Samsung approves your app for production, enable Developer Mode in the Samsung Health app so the permission flow works on your test build. If setProvider("samsung") returns false, the device, the Samsung Health app, or Developer Mode is not set up.

Step 5: Request Permissions

Request access to specific health data types. The type IDs are string-based:
Make sure to call setActivity() on the SDK before requesting authorization, so the SDK can launch the permission dialog from the correct Activity context.

Step 6: Start Background Sync

Enable background sync to keep data flowing even when your app is in the background:

Controlling Sync History Depth

By default, the SDK syncs all available historical data on the first sync. Use the syncDaysBack parameter to limit how far back the sync goes:

Background Sync Behavior

Manual Sync

Trigger an immediate sync:

Stop Sync

Log Level

Control SDK log output using the logLevel property. By default, the SDK uses OWLogLevel.DEBUG, which outputs logs only in debuggable builds:
Set OWLogLevel.ALWAYS during development or when troubleshooting sync issues in production. Switch to OWLogLevel.NONE if you want to suppress all SDK output.

Lifecycle Management

Notify the SDK of app lifecycle changes for optimal sync behavior:

Samsung Health Production Requirements

Samsung Health works on your development build with Developer Mode - for read access (what Open Wearables needs) you only need a Samsung account, no partnership request. Production adds a requirement: the same code runs, but the permission flow aborts on release builds until both of these are true:
  1. Your partnership request is approved by Samsung. Submit it through Samsung’s app creation process, providing your app’s package name and release signing key signature.
  2. Your release signing key is on Samsung’s allowlist. Samsung matches package name + SHA-256 at runtime. Get the fingerprint from your release keystore - and if you use Play App Signing, register the Play app signing key (Play Console → Setup → App integrity → App signing), not your upload key:
IllegalStateException: Could not get policy for {package} on a release build means Samsung has not matched your app - the partnership is not approved, or the running build’s package name or signing certificate does not match what Samsung registered (a common Play App Signing pitfall). Confirm all three, then contact Samsung Developer Support.
None of this applies to Health Connect ("google"), so you can ship with Health Connect first and add Samsung Health once approval lands.

Background sync

Samsung Health does not use the android.permission.health.* declarations Health Connect relies on - permissions are granted through Samsung Health’s own dialog, so no extra manifest permissions are needed for the Samsung provider. Background sync uses the same WorkManager and foreground-service mechanism as Health Connect; see Troubleshooting for the battery-optimization and POST_NOTIFICATIONS requirements that affect it.

Complete Integration Example

Here’s a complete ViewModel showing the full integration:

Using the ViewModel

Data Sync Endpoint

The SDK sends health data to:
The payload includes a provider field ("samsung" or "google") and the SDK version:
Data is automatically normalized to the Open Wearables unified data model and can be accessed through the standard API endpoints.

Next Steps

Troubleshooting

Common issues and solutions for Android.

Data Types

Available health metrics and data formats.