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).

## Availability checks

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-powered device. If it isn't, Health Connect triggers an
availability check to determine whether the user's device is compatible.

## Permission checks

Health Connect requires you to request the user's permission to read and
write their health and fitness data on a per-app basis. It also lets you
see what permissions have already been granted or denied by the user.

## Reading with Health Connect

### Foreground reading

You can normally read data from Health Connect when your app is
in the foreground. In these cases, you may consider using a foreground service
to run this operation in case the user or system places your app
in the background during a read operation.

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 prefer your app to run without
interruptions, use a
[foreground service](https://developer.android.com/develop/background-work/services/fgs):

- [`FOREGROUND_SERVICE_TYPE_HEALTH`](https://developer.android.com/reference/android/content/pm/ServiceInfo#FOREGROUND_SERVICE_TYPE_HEALTH): Allows app to remain in
  the foreground to collect sensor data, such as a workout app that continues
  to collect data even when the user puts the app in the background.

- [`FOREGROUND_SERVICE_TYPE_SHORT_SERVICE`](https://developer.android.com/reference/android/content/pm/ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE): A generic-type
  service that allows an app to continue to collect critical data for
  tasks that take less than three minutes,
  even if the user places the app in the background before it completes.

### Background reading

You can request that your application run in the background and read data from
Health Connect. If you request the
[Background Read](https://developer.android.com/health-and-fitness/guides/health-connect/develop/read-data#background-read-example)
permission, your user can grant your app access to read data in the background.