Skip to main content

Quick Start

Get started with the basic implementation

1. Overview

Features

  • Get authorization.
  • Register users.
  • Sync Samsung Health summaries and events.
  • Schedule automatic Samsung Health data syncs in background.

Restrictions

  • Samsung Health Data SDK requires Samsung Health v6.29 or later version installation.
  • Samsung Health runs on devices with Android 10 (API level 29) or above. It is available on all Samsung smartphones and also non-Samsung Android smartphones.
  • The SDK doesn’t support an emulator.

Android Studio

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

Dart and Flutter

This package was developed with the following sdk constraints:

  • dart: >=3.0.0 <4.0.0
  • flutter: >=3.0.0

2. Installation

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

minSdk 26
targetSdk 35

Core Version Samsung Version

flutter pub add rook_sdk_core
flutter pub add rook_sdk_samsung_health

In your build.gradle (app module) copy the samsung-health-data.aar file to your project libs directory and include it as a dependency:

dependencies {
implementation(files("$rootDir/libs/samsung-health-data-api-1.0.0-b2.aar"))
}

Samsung Health Data also needs the following dependencies to work correctly:

dependencies {
implementation("com.google.code.gson:gson:2.13.0")
}

Enable developer mode on your device.

3. Initialize SDK

void initialize() {
final configuration = RookConfiguration(
clientUUID: clientUUID,
secretKey: secretKey,
environment: environment,
// If true background sync will start when the SDK is initialized
enableBackgroundSync: true,
);

// Enable logging only on debug builds
if (isDebug) {
RookSamsung.enableNativeLogs();
}

RookSamsung.initRook(configuration).then((_) {
// Success
}).catchError((error) {
// Handle error
});
}
tip

You should only initialize the SDK once per app launch.

tip

We recommend you to ask your users if they want to enable the automatic sync and steps tracking, then save their preference in local storage and set enableBackgroundSync conditionally.

4. Update userID

Update the userID:

void updateUserID() {
RookSamsung.updateUserID(userID).then((_) {
// Success
}).catchError((exception) {
// 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 requesting permissions check that Samsung Health is installed and ready to be used:

void checkAvailability() {
RookSamsung.checkSamsungHealthAvailability().then((availability) {
// Success
}).catchError((exception) {
// Handle error
});
}

Once you have confirmed that availability == SamsungHealthAvailability.installed, ask permissions:

void requestPermissions() {
final samsungPermissions = [
SamsungHealthPermission.activitySummary,
SamsungHealthPermission.bloodGlucose,
SamsungHealthPermission.bloodOxygen,
SamsungHealthPermission.bloodPressure,
SamsungHealthPermission.bodyComposition,
SamsungHealthPermission.exercise,
SamsungHealthPermission.exerciseLocation,
SamsungHealthPermission.floorsClimbed,
SamsungHealthPermission.heartRate,
SamsungHealthPermission.nutrition,
SamsungHealthPermission.sleep,
SamsungHealthPermission.steps,
SamsungHealthPermission.waterIntake,
];

RookSamsung.requestSamsungHealthPermissions(samsungPermissions).then((requestPermissionsStatus) {
if (requestPermissionsStatus == RequestPermissionsStatus.alreadyGranted) {
// Permissions already granted, update your UI
} else {
// Permissions dialog has been displayed
}
}).catchError((error) {
// Handle error
});
}

6. Schedule a background sync

void enableBackgroundSync() async {
try {
await RookSamsung.enableBackground(enableNativeLogs: isDebug);

// Background sync enabled
} catch (error) {
// Handle error
}
}
tip

We recommend adding an extra call to enableBackground in the main method:

void main() {
// Ensure that the plugin is ready
WidgetsFlutterBinding.ensureInitialized();

if (Platform.isAndroid) {
enableAndroidBackgroundSync();
} else {
enableIOSBackgroundSync();
}

runApp(App());
}

void enableAndroidBackgroundSync() async {
try {
final userAllowedBackgroundSync = await AppPreferences().getUserAllowedBackgroundSync();

if (userAllowedBackgroundSync) {
await RookSamsung.enableBackground(enableNativeLogs: isDebug);
}
} catch (error) {
// Log
}
}

void enableIOSBackgroundSync() async {
// Go to IOS documentation to learn how to enable background sync
}

Continue learning

Next steps

Prepare for release

Additional resources