The latest version of Wear OS includes a new 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
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
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.
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.
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 taken at a single point in time, such as
SPEED, and data taken over a time period,
Event is a combination of a data type, a condition that should be
satisfied, and a trigger type. An event is triggered when that data type meets
the specified condition. Apps can register to be notified of that occurrence,
such as when the user's aggregate step count surpasses a certain threshold.
The trigger type determines whether the app is notified only on the next
occurrence of the event (with
EventType.TriggerType.ONCE), or on every
Health Services treats exercise as a first-class feature and supports a
ExerciseTypes. 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.
Goals and milestones
Similar to events, goals and milestones are each a combination of a
and a condition. A goal is triggered once when the condition is met. A milestone
is configured with both an initial trigger amount and a period amount, so it
will trigger once when the initial condition is met, and again each time the
period amount is achieved. For example, to set a milestone every time the user
runs 1 kilometer, use 1km as the initial threshold and 1km as the period amount.
Create apps using Health Services
Create apps using Health Services in the ways described in the following sections.
PassiveMonitoringClient, your app registers a
PendingIntent and uses a
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.
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.
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
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.