Skip to main content

Quick Start

Get started with the basic implementation

1. Overview

Features

  • Get authorization.
  • Register users.
  • Sync Health Connect summaries and events.
  • Schedule automatic Health Connect data syncs every time the app is launched or in background.
  • Track and upload steps from Android System in background.

Restrictions

Health Connect (HC) known issues

Health Connect is a container of data where apps can READ and WRITE from and into it, that means for the ideal scenario both the provider (application that writes) and the consumer (application that reads) have to be working correctly.

There have been numerous reports of apps failing to synchronize data with Health Connect due to technical issues within the HC platform itself or because of the providers.

Also is important to clarify that Health Connect does not have real-time behaviour the availability of the data depends on each provider business rules for synchronization.

Finally, we'd like you to remember that we are always improving our SDK to offer the best experience, however, the Health Connect platform is in an alpha state, so it's functionality sometimes may not always be the expected.

Samsung Health

For Samsung Health we recommend to use our direct integration; Rook Samsung SDK which provides more accurate results and does not have the limitations of the Health Connect platform.

Android Studio

The SDK requires Android Studio Koala Feature Drop | 2024.1.2 Patch 1 or higher.

2. Installation

In your build.gradle (app) set your min and target sdk version like below:

minSdk 26
targetSdk 35

In your build.gradle (app module) add the required dependencies.

  • Latest version: Maven Central Version
  • Latest stable version: 2.4.0
  • LTS version (supported until May 31, 2026): 2.4.0
implementation("com.rookmotion.android:rook-sdk:version")

3. Initialize SDK

val environment = if (BuildConfig.DEBUG) RookEnvironment.SANDBOX else RookEnvironment.PRODUCTION
val configuration = RookConfiguration(clientUUID, secretKey, environment)

// Enable logging only on debug builds
if (BuildConfig.DEBUG) {
rookConfigurationManager.enableLocalLogs()
}

rookConfigurationManager.setConfiguration(configuration)
rookConfigurationManager.initRook().fold(
{
// Success
},
{
// Handle error
}
)
tip

You should only initialize the SDK once per app launch.

4. Update userID

Update the userID:

rookConfigurationManager.updateUserID(userID).fold(
{
// Success
},
{
// Handle error
}
)
info

Any call to updateUserID with a different userID will override the previous userID and reset the sync status, so if you are using Automatic Sync all health data will synchronize again.

5. Request permissions

Check availability

Before proceeding further, ensure the user's device is compatible with Health Connect and check if the APK is installed. Call checkHealthConnectAvailability:

StatusDescriptionWhat to do
INSTALLEDAPK is installedProceed to check permissions
NOT_INSTALLEDAPK is not installedPrompt the user to install Health Connect.
NOT_SUPPORTEDThis device does not support Health ConnectTake the user out of the Health Connect section
val message = when (rookPermissionsManager.checkHealthConnectAvailability()) {
HealthConnectAvailability.INSTALLED -> "Health Connect is installed! You can skip the next step"
HealthConnectAvailability.NOT_INSTALLED -> "Health Connect is not installed. Please download from the Play Store"
else -> "This device is not compatible with health connect. Please close the app"
}

Once you have confirmed that availability == checkHealthConnectAvailability.INSTALLED, ask permissions:

rookPermissionsManager.requestHealthConnectPermissions().fold(
{
when (it) {
RequestPermissionsStatus.ALREADY_GRANTED -> {
// Permissions already granted, update your UI
}

RequestPermissionsStatus.REQUEST_SENT -> {
// Permissions dialog has been displayed
}
}
},
{
// Handle error
}
)

6. Schedule a background sync

rookBackgroundSyncManager.schedule(enableLogs = isDebug)
tip

We recommend adding an extra call to schedule in the onCreate callback of your Application class:

class MyAplication : Application() {
override fun onCreate() {
super.onCreate()

// It's a good practice to ask your users if they want to enable this behaviour
// and wrap this line inside an if which checks a preferences-stored flag
if (userAllowedBackgroundSync) {
RookBackgroundSyncManager.schedule(this, enableLogs = isDebug)
}
}
}

Continue learning

Next steps

Prepare for release

Additional resources