The following describes the main functionalities of the Health Connect API.
CRUD operations on record and data synchronization
The platform provides standard insert, update, and delete functions for recorded data. Health Connect also includes a functionality that allows client apps to synchronize data out of Health Connect. This produces a log of data changes that indicates to the developer and user whether certain data types have been inserted or deleted by other apps.
Simple aggregation functions
The platform allows clients to apply an aggregation function over underlying data, performing the following functions:
- Providing the average, minimum or maximum values (i.e., the minimum and maximum heart rate during an activity session).
- Providing the sum total (i.e., the total step count within a daily interval).
- Providing a simple count of the number of underlying measurements (e.g., the number of activity sessions in a given week).
- Providing the total duration on supported data types (e.g. time spent in deep sleep this week or total duration of activity sessions today).
Health Connect is compatible with Android SDK version 28 (Pie) and higher. The SDK allows client apps to determine whether the Health Connect API is on the user’s Android device. If it isn’t, Health Connect triggers an availability check to determine whether the user’s device is compatible.
Health Connect requires you to request the user’s permission to read and/or write their health and fitness data on a per-app basis. It also allows you to see what permissions have already been granted or denied by the user.
Reading with Health Connect
Only applications running in the foreground can read data with Health Connect. This restriction is in place to further strengthen user privacy. Health Connect notifies and assures users that it does not have background read access to their data and can only read and access data in the foreground.
For situations in which your app may expect an interruption, such as displaying a reading in your application, read directly from Health Connect to your client application.
For situations in which you may prefer for your app to run without interruptions, such as reading a range of data from Health Connect then writing and uploading it elsewhere, use a ForegroundService, rather than an Activity where it can easily be dismissed.