Health Services on Wear OS

Wear OS includes a service called Health Services. Health Services acts as an intermediary to the various sensors and related algorithms on the device to provide apps with high-quality data related to activity, exercise, and health.

See the Health Services sample repository on GitHub for example fitness apps.

How Health Services helps app developers

Without Health Services, apps had to connect to one or multiple sensors, configure each of them appropriately, receive raw sensor data, and use their own algorithms to derive meaningful information. For example, an app might register for updates of Sensor.TYPE_PRESSURE to get the current air pressure, use it to compute the current altitude, and aggregate this data over time to show the elevation changes during a user's activity session.

Health Services automatically configure all fitness and health related sensors appropriately for the use-case, collect sensor data, and compute metrics like heart rate, distance, calories, elevation, floors, speed, pace, and more. Apps can register for this data directly from Health Services.

with-health-services

Some of the benefits of using Health Services include the following:

  • Take advantage of powerful algorithms running natively on the platform.
  • Conserve battery by using sensor configurations from Health Services that are optimized for power efficiency.
  • Ensure data consistency across all applications on the same device by using standardized platform computations.
  • Enable activity-aware experiences, including the ability to detect an ongoing exercise started from another app.

All of these allow developers to focus on developing unique features and user experiences, while relying on the platform to provide robust and consistent metrics in a power-efficient manner.

Health Services concepts

Keep the following concepts in mind when developing with Health Services.

Data types

Health Services offers a variety of data collected from all the available sources on the device and updated continuously. These data types fall into two broad categories: data sampled at a single point in time, such as HEART_RATE_BPM, and data taken over a time interval, such as DISTANCE.

Events

Apps receive events when the user reaches a certain goal state, such as falling asleep or running a particular distance.

Exercise types

Health Services treats exercise as a first-class feature and supports a multitude of ExerciseTypes such as running or skiing. While an exercise is in progress, Health Services can collect metrics on selected DataTypes and report back to the app that is managing the exercise.

For more information, see the full list of Exercise types.

Create apps using Health Services

Create apps using Health Services in the ways described in the following sections.

Passive experiences

With PassiveMonitoringClient, your app supplies a ComponentName for BroadcastReceiver to receive updates about a data type or an event. This is suited for long-lived experiences where data updates are relatively infrequent and spread over time.

See Passive data updates for more information.

Active experiences

With MeasureClient, your app registers listeners to receive rapid data updates. This is suited for short-lived experiences, such as while the user is looking at your app UI. It is important that apps try to minimize the time spent with a registered listener because it increases the sensor sampling rate and thus increases power consumption. This API is not intended for background capture or workout tracking. For example, MeasureClient can be used for apps that measure blood oxygen levels (SpO2).

With ExerciseClient, your app can manage a user's workout, set exercise goals, and listen for updates about the current exercise state. Your app can also receive rapid data updates through this API, as long as the exercise belongs to your app. ExerciseClient can be used for apps such as a running app, that allows you to record your run, display live metrics on your device, and record data for further analysis.

See Active data and exercises for more information.

Testing with synthetic data

To test that your app is receiving data updates from Health Services, manually set your device to emit data as if a user is engaged in an exercise.

See Testing with synthetic data for more information.