This page describes the main functions 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 functionality that allows client apps to synchronize data out of Health Connect. This produces a log of data changes that shows the developer and user whether certain data types have been inserted or deleted by other apps.
Basic aggregation functions
Clients can apply an aggregation function over underlying data, providing the following:
- The average, minimum or maximum values (for example, the minimum and maximum heart rate during an activity session).
- The sum total (for example, the total step count in a daily interval).
- A simple count of the number of underlying measurements (for example, the number of activity sessions in a given week).
- The total duration on supported data types (for example, 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.