Mobile SDK Installation
Learn about the minimum runtime and build-time requirements of Junction Mobile SDKs, and how to add them into
your project through your package dependency manager.
Junction Health SDK
Learn about the initial setup required by Junction Health SDK, and the API exposed by Junction Health SDK
for managing and inspecting health data permissions and automatic data sync.
Getting Started
To enable this integration, you would need to integrate Junction Core SDK and Junction Health SDK into your Native Android or React Native mobile app.Add Junction SDKs as dependencies
Samsung Developer Program enrollment and project setup
Before you can build against Samsung Health, you need a Samsung account, Samsung Developer Program enrollment, and the
Samsung Health Data SDK AAR. Follow the Samsung Health project setup section below.
Integrate with Junction Mobile SDK Authentication
Follow the SDK Authentication guidance to integrate your app with the authentication
mechanism of Junction Core SDK.
Configure Health SDK and ask user for read permissions
Follow the Junction Health SDK guidance to
configure the Health SDK and to
ask for health data read permissions from your user.
Health data sync is activated only on
VitalResources which you have asked permissions from your user for. If you
did not ask for permissions, data sync would not occur.Samsung Health is read-only through Junction Health SDK. Do not request write permissions or use the write APIs with
samsung_health.[Optional] Customize the Foreground Service notification
Follow the Running as Foreground Service guidance below to
customize the Foreground Service notification which may be shown by the Android OS during
any prolonged health data sync attempts.
[Optional] Configure Background Sync
Follow the Background Sync guidance below to
configure regular background sync.
Samsung Health constraints
Testing internally
❌ You cannot test the integration in an Android emulator, since Samsung Health is not available for emulators. ✅ You can test the integration on an Android device you control through the Samsung Health Developer Mode.Going Production
Before shipping Samsung Health support to production, you must have obtained for partnership approval through the Samsung Health development process. The permission request flow will abort for your app, until:- Your partnership request has been approved by Samsung; AND
- Their developer support team has added your app signing key signature to the allowlist.
Samsung Health project setup
Samsung distributes the Samsung Health Data SDK as an AAR, and the partnership and support flows are hosted on Samsung Developer. Before integrating Samsung Health:- Create a Samsung account and sign in on Samsung Developer Dashboard.
- Enroll in the Samsung Developer Program and review Samsung Health’s current onboarding and partnership requirements.
- Download the Samsung Health Data SDK AAR from the official Samsung Health Data SDK page.
- Add the downloaded AAR to your repository, for example at
android/vendor/samsung-health-data-api-1.0.0.aar.
- Native Android / Bare RN
- Expo / React Native
For Native Android and bare React Native host apps, configure the Android root project so the Vital Samsung Health
integration can resolve the downloaded AAR.Add the AAR path to your Android root Apply the Samsung Health settings plugin in your Android root Apply the Samsung Health project plugin in your Android root
gradle.properties:android/gradle.properties
settings.gradle:android/settings.gradle
build.gradle:android/build.gradle
Use the same plugin version as your
io.tryvital:vital-samsung-health dependency. The samsungHealthAarPath
value is resolved relative to the Android root project.Prepare your app architecture
- Native Android
- React Native
When requesting permission using the
ActivityResultContract created by Junction Health createPermissionRequestContract(), you must launch
the contract using AndroidX Activity Result API.Synchronization
Sync On App Launch
When your app resumes from background (i.e., having no Activity), Junction Health SDK triggers a data sync on all the resources to which the user has granted read permission. The SDK imposes a 2-minute throttle on automatic data sync. This is to prevent rapid app switching from causing an excessive amount of data sync work being scheduled.Junction Health SDK relies on the AndroidX ProcessLifecycleOwner
to get notified of your app’s resumption.
Running as Foreground Service
You cannot opt-out of this behaviour.
- Native Android
- React Native
Register your custom An example
SyncNotificationBuilder as soon as your app process is created. One way to ensure this is through the AndroidX Startup
library. You can define an Initializer of your own that depends on the SDK VitalSamsungHealthInitializer.An example App Startup Initializer implementation
An example SyncNotificationBuilder implementation
Background Sync
Junction Health SDK supports an opt-in Android Background Sync feature. It provides a continuous monitoring experience with Samsung Health, identical to Android Health Connect, similar to Background Delivery for Apple HealthKit on iOS.Sync Frequency
The Sync On App Launch behaviour is always-on. When Background Sync is enabled, the SDK additionally schedules hourly sync using the Android Exact Alarms mechanism. The OS has full discretion on whether to honour or defer the time as scheduled by the Junction Health SDK. This includes the policies of the base Android OS, as well as any vendor-specific OS augmentation. For example, the device may enter Doze mode during device inactivity. Doze mode would batch and defer most Exact Alarms and other background work to run at a lower frequency.Not to be confused with Alarm Clock apps, Exact Alarm is the technical name of an Android framework for scheduling
app wake-ups in background at certain wall clock time. It is the Junction Health SDK being silently “alarmed” in background.Your user will not be alarmed hourly as a result of enabling Background Sync.However, if the data sync took longer than 10 seconds, the OS might nudge them of this occurrence with a user-visible notification.
The notification content is configurable by you — see the “Running as Foreground Service” section for more details.
Runtime Permission Request
Since Android 12 (API Level 31), scheduling Exact Alarm (SCHEDULE_EXACT_ALARM) requires a runtime permission request from the user.
More specifically:
- The user must go through an interactive flow to grant the “Alarms & Reminders” permission.
- This flow is also reachable through the “Alarms & Reminders” section in Android Settings.
- The user may refuse to grant the “Alarms & Reminders” permission.
- The user may revoke the “Alarms & Reminders” permission through Android Settings at any time.
USE_EXACT_ALARM permission was introduced. This permits your app to
schedule Exact Alarms without interactive permission requests.
Here is a matrix summarizing the Exact Alarm permission request requirements:
| Android OS | API Level | Requirements |
|---|---|---|
| Android 11 or below | <=30 | No interactive permission request. |
| Android 12 | 31, 32 | SCHEDULE_EXACT_ALARM: Requires a runtime permission request. Revokable. |
| Android 13 and above | >=33 | App must declare either:
|
Updating your AndroidManifest.xml
Samsung Health does not use the
android.permission.health.* manifest declarations required by Health Connect.
For Junction Health SDK, the manual manifest change required for Samsung Health Background Sync is the Exact Alarm
permission choice below.uses-permission claims:
- The SCHEDULE_EXACT_ALARM route
- The USE_EXACT_ALARM route
Make sure you read and understand Runtime Permission Request before moving forward.
This option is mutually exclusive with
USE_EXACT_ALARM in the second tab.Enabling Background Sync
- Native Android
- React Native
You can enable Background Sync through
enableBackgroundSyncContract() (an AndroidX ActivityResultContract).If the runtime requires an interactive permission request, this contract will launch
an Android Intent to request the “Alarms & Reminders” permission. The contract result is a boolean, indicating whether
or not the Background Sync has been enabled successfully. For example, if the user did not grant the permission during the said Android Intent,
the contract returns false.Otherwise, the contract returns true synchronously when no user interaction is required.You can also inspect if Background Sync has been enabled through the isBackgroundSyncEnabled property.Disabling Background Sync
- Native Android
- React Native
You can disable Background Sync through the
disableBackgroundSync() method.You can also inspect if Background Sync has been disabled through the isBackgroundSyncEnabled property.Miscellaneous
When yousignOut() a user, Junction SDK will automatically disable Background Sync.