Accessing Samsung Health Data through Health Connect
Samsung Developer
Health Connect is a platform that enables you to integrate Samsung Health data with your applications, creating new opportunities for health applications that enhance the user's journey towards better health. Using the Health Connect APIs, you can, for example, retrieve a user's Samsung Health data, such as their exercise, sleep, and heart rate information, and send data to the Samsung Health application.
This is the first blog post in a series introducing you to the Health Connect API features and how you can use them in your applications. Let's begin by looking at how Health Connect interacts with Samsung Health data and the basic workflow. Understanding this is essential for creating applications that use data from Samsung Health and Health Connect.
Samsung Health
Samsung Health is an application that can be installed on Android smartphones and tablets, and on Galaxy Watches. It can use the sensors on the device, including the Galaxy Watch's BioActive sensor, to measure the user's overall health data, including steps, exercises, heart rate, sleep, blood oxygen saturation and body composition.
The Samsung Health application is installed on both the Galaxy Watch and a smartphone. The application synchronizes the measurements between both devices and manages the user's health data securely on them.
Health Connect
Since the Samsung Health application supports various useful health data types and gathers data from all connected devices, developers have been interested in obtaining access to that data. Consequently, Samsung collaborated with Google to build the Health Connect platform, which was released in May 2022. Health Connect enables applications to share health and fitness data across Android devices with the user's consent. For more information about Health Connect, see Health Connect Guide and Health Connect APIs.
Samsung Health has supported synchronizing data with Health Connect since application version 6.22.5, released in October 2022. The Health Connect APIs support devices using Android SDK 28 (Pie) or higher.
Once the user has connected Samsung Health to Health Connect, new or updated data in Samsung Health is shared to Health Connect. This means that your applications can use the Health Connect APIs to access Samsung Health data. Samsung Health synchronizes health data with Health Connect in both directions:
- When Samsung Health has new or updated data, it writes the data to Health Connect.
- When Health Connect has updated data, Samsung Health retrieves it.
For example, a blood glucose meter connected to Samsung Health measures the user's blood glucose level. This data is saved in Samsung Health and then sent to Health Connect. Similarly, whenever there is new blood glucose data in Health Connect, Samsung Health retrieves that data and saves it in Samsung Health.
To demonstrate how data synchronization works, let's walk through an example of adding nutrition information to Samsung Health.
- To start data synchronization between Samsung Health and Health Connect, you must enable it in the Samsung Health application on your Android device. From the Settings menu, select Health Connect. If Health Connect is not installed, you are prompted to install it.
- The first time you access the Health Connect menu item in Samsung Health, tap Get started.
- You are asked to grant permissions to share your Samsung Health data with Health Connect. Select the data you consent to sharing and tap Allow.
- To test the data synchronization, in Samsung Health, go to Food tracker and create some nutrition data.
- In Samsung Health, go to Settings > Health Connect, and select Data and access. If Health Connect has received nutrition data from Samsung Health, a Nutrition item appears in the Browse data list.
- To view the synchronized data, select Nutrition.
Figure 3: Get started screen
Figure 4: Data sharing consent
Samsung Health and Health Connect are now linked and data is shared between them.
Figure 5: Nutrition data input
Figure 6: Synchronized nutrition data
Figure 7: Nutrition data in Health Connect
Data synchronization timing
Data synchronization between Samsung Health and Health Connect occurs on the smartphone side. To take advantage of health data collected by a Galaxy Watch, you must understand at which times the Galaxy Watch sends its data to the Samsung Health smartphone application.
Figure 8: Data synchronization between watch and smartphone
New or updated health data on each connected device is generally synchronized with Samsung Health in the following situations:
- The Galaxy Watch reconnects with the smartphone
- The user opens the Samsung Health application home screen on the smartphone
- The user pulls down on the Samsung Health application home screen on the smartphone
However, some types of health data are synchronized differently:
- For battery conservation reasons, continuous heart rate data from the Galaxy Watch is not sent to the Samsung Health application on the smartphone immediately. However, manual heart rate measurements on the watch are synchronized immediately.
Enabling Settings in Samsung Health
To synchronize health data between Samsung Health and Health Connect please consider:
- Using the latest Samsung Health.
If you're interested in Galaxy Watch's data, check its version too. - Allowing data permissions through the following path:
Samsung Health > Settings > Health Connect > App permissions > Samsung Health
(Note that you must enter from the Samsung Health settings) - Synchronizing Samsung Health data in:
Samsung Health > Settings > Sync with Samsung Cloud > Switch to 'On'.
Accessing Health Connect APIs
If the user has synchronized their Samsung Health data with Health Connect, you can use the Health Connect APIs to interact with it in various ways. For example:
- Read and write data: You can retrieve data that has been shared from Samsung Health to Health Connect and send data to Health Connect to be synchronized to Samsung Health.
- Delete specific data records: You can remove a specific data point or data of a specific type within a time interval.
- Aggregate and filter data: You can filter the retrieved data by type or tag and analyze it, such as determining the average, maximum, minimum or sum of the values.
- Session data: You can group data into sessions by time interval, such as to generate a sleep or activity session report.
The following table lists the various health data that can be synchronized between Samsung Health and Health Connect.
All steps | StepsRecord
|
Blood glucose | BloodGlucoseRecord
|
Blood oxygen | OxygenSaturationRecord
|
Blood pressure | BloodPressureRecord
|
Exercise, session | ExerciseSessionRecord
|
Exercise, calories | TotalCaloriesBurnedRecord
|
Exercise, distance | DistanceRecord
|
Exercise, heart rate | HeartRateRecord
|
Exercise, power | PowerRecord
|
Exercise, speed | SpeedRecord
|
Exercise, VO2max | Vo2MaxRecord
|
Heart rate | HeartRateRecord
|
Nutrition | NutritionRecord
|
Sleep session Sleep stage |
SleepSessionRecord
|
Weight | WeightRecord
|
Weight, body fat | BodyFatRecord
|
Weight, basial metabolic rate | BasalMetabolicRateRecord
|
Weight, height | HeightRecord
|
Samsung Health’s activity tracker data are not synchronized to Health Connect.
To get started with implementing Health Connect API functionality in your application:
- Add the latest version of the Health Connect API library dependencies to your application's "build.gradle" file, for example:
implementation "androidx.health.connect:connect-client:1.1.0-alpha02"
- Declare the Health Connect application package name in your "AndroidManifest.xml" file.
- Check that the user has the Health Connect application, then create the "HealthConnectClient" instance.
- Declare the permissions for the health data types you want to use.
Now your application is ready to use the Health Connect APIs.
Other blog posts in this series explore various Health Connect API use cases in more detail.