Programming Guide Sep 13, 2018

Samsung Health Android SDK helps Samsung Health's partners to share health data safely and to create useful health applications. Samsung Health has a health data store where its data can be shared with other partner apps after the user’s consent. It supports Android devices with Lollipop 5.0 including non-Samsung devices.

Figure: Samsung Health integration with SDK

Refer to the following table for Samsung Health Android SDK glossary.

Term Description
Health Data framework It provides useful features to handle the user’s health data. It is included in Samsung Health and its interface is provided with Samsung Health Android SDK. An app that uses the SDK works with Samsung Health.
Samsung Health An application that helps monitor the user’s activities and helps the users to have a healthier life through monitoring walking steps, exercise, heart rate, and etc. It can be downloaded from the app market like Google Play or Galaxy Apps.
The term is italicized to be easily distinguished.
Table: Glossary

The SDK provides the following packages.

  • Health Data

  • Health Service

This document contains descriptions for the SDK’s Health Data. See the Health Service’s documents if you want to launch one of its trackers or post your app’s tracker on Samsung Health.

Health Data Framework

The health data framework of Samsung Health Android SDK has the following features:

  • Health Data Store

    • Handling the connection to Samsung Health
    • Inserting, reading, updating, or deleting health data
    • Storing data based on unified units. See API Reference’s descriptions for each data type
  • Health Data Type

    • Platform-defined and custom data type
  • Privacy

    • Granting permission based on the user’s consent to read or write the specific data type

Architecture

The SDK’s health data framework is designed to provide safe access of its data and to have a seamless health service to the user. The following figure shows the health data framework’s architecture.

Figure: Health data framework architecture
Health Data Framework

The health data framework is included in Samsung Health. Applications can access the user’s data that are stored in Samsung Health through the SDK. It keeps the user’s health data safely. Health data from various source devices having pedometer, accelerator, or heart rate sensors are inserted to the health data framework with the unified data unit. The data can be read by the SDK. Updating or deleting data is available if the app inserted the data.

Partner Apps

An app that uses Samsung Health Android SDK works with Samsung Health after a partner approval. In a test use Samsung Health's developer mode. If your app is used in private and users are very small, the developer mode may be a simple solution.

To skip the dev mode, get an approval as Samsung Health’s partner. The partner app request is available in the developer site. Data sync with Samsung Health should work well before the partner app request. The SDK’s DataViewer tool and app checklist can help the app test efficiently.

Figure: Class diagram for HealthDataStore

The figure above shows the class and interface relationships in Health Data. Detailed descriptions for each class and interface are in the API Reference.

HealthDataService.initialize()

It initializes the health data service. APIs of the com.samsung.android.sdk.healthdata works properly after calling it without an exception.

HealthDataStore

It handles the connection to the data storage of the device. It receives its connection result with HealthDataStore.ConnectionListener. Most requests require the connection to the health data store.

HealthDataResolver

The health data framework provides classes and interfaces to insert, read, update, or delete the data. HealthDataResolver is a central class to handle the health data. It sends a data request with related request interfaces.

The query result can be received immediately with HealthDataHolder.BaseResult, HealthDataResolver.ReadResult or HealthDataResolver.AggregateResult. Or it can be received asynchronously with HealthResultHolder.ResultListener. See Health Data Store for more information.

Application developers can use platform-defined data types that Samsung Health Android SDK provides. See Health Data Type for more information. Especially HealthConstants.Common, the base interface of predefined data types, contains the following mandatory properties for health data.

  • Unique ID of health data

  • Created and updated time of health data

  • Application package name

  • Device that provides health data

Figure: Class diagrams of SessionMeasurement data types
Figure: Class diagrams of DiscreteMeasurement

The health data can be accessed with the user’s consent. The following figure shows the relationship between classes and interfaces related to HealthPermissionManager. It requests permissions to the user with HealthPermissionManager.PermissionKey to read or write for the specific health data type. The permission result can be received synchronous or asynchronously. See Privacy for more information.

Figure: Class diagram related to HealthPermissionManager

The SDK’s Health Data library provides the following package:

  • com.samsung.android.sdk.healthdata

Main interfaces and classes in the library are described in the following table. See the API reference for details.

com.samsung.android.sdk.healthdata
Interface / Class Description
HealthConnectionErrorResult This class handles errors for connection failure to the health data store.
HealthConstants This class defines constants of health data and contains interfaces for various kinds such as the step count or exercise.
HealthData This class is an object for a health data type, e.g., the blood pressure or weight. Quantitative and qualitative values can be defined for the specific health data type based on its data structure definition. It is used to manage health data with HealthDataResolver.
HealthDataObserver This class defines an observer to handle health data changes.
HealthDataResolver This class accesses health data to insert, read, update, and delete with the filter and aggregate functions.
HealthDataService This class initializes the health data service.
HealthDataStore This class handles the connection to the data store in the device.
HealthDataUnit This class provides unified units for the health data store.
HealthDataUtil This class provides useful utility APIs.
HealthDevice This class contains detailed device information that provides health data.
HeatlthDeviceManager This class manages devices related health data.
HealthPermissionManager This class requests permission to read or write health data for the specific health data type.
HealthResultHolder This interface represents the result of invoking method.
HealthUserProfile This class provides the user information.
Table: Interfaces and classes of com.samsung.android.sdk.healthdata