Tag Archives: Health Services

Peloton increased its multi-device support and saw an uptick in user engagement

Posted by the Android team

The Peloton App makes it easy for people to work out wherever they want, whenever they want. From living room yoga classes to guided audio runs outdoors, Peloton strives to create an engaging exercise experience that works for anyone, anywhere.

For Peloton, creating convenient workouts means making the Peloton App more accessible across surfaces. So after receiving numerous requests to upgrade its Android app experience from its community, along with the Pixel Watch announcement at Google I/O in 2022, the Peloton team saw an opportunity to boost the app’s support across the entire Android ecosystem, ensuring its Members receive a seamless Peloton experience on all their devices.
Quote card with text reads, 'We want to meet Members where they are and on all the devices they own'- Stefan Haaker, senior Android engineer at Peloton. Peloton logo.

Building the Wear OS experience

Peloton developers began updating the app’s multi-device support by creating a modern watch application for Wear OS devices using Compose for Wear OS. With the Compose toolkit, Peloton developers were able to quickly build a watch experience that met Wear OS guidelines. “The Wear OS app was our first usage of Compose in production,” said Stefan Haacker, a senior Android engineer at Peloton. “We really enjoyed how much more productive it made us.”

The Peloton team released the first wearable app version just after the Pixel Watch launched. They worked tirelessly to get the app ready between the announcement of the Pixel Watch and its launch. Thanks to the Jetpack Compose toolkit, Peloton developers were able to rapidly and efficiently prepare the app in record time.

The new wearable app gave Peloton Members more options for monitoring their heart rate in real time. Using the Data Layer API to synchronize information between wearables and the Peloton App, Members can now view their heart rate across devices—from their phones to their watches to their bikes—as they take a Peloton class.

“Before the Wear OS app was released, only a small percentage of Android Members worked out with a heart rate monitor (HRM). After releasing Peloton on Wear OS, the app had a 6X increase in HRM usage in just a few months,” said Stefan. “For Peloton, HRM usage correlates with a better user experience, increased user engagement, and more workouts a month.”

With more Members tracking their health and fitness data through the new Peloton app, it was important for the Peloton team to give them better access to that data. That’s why Peloton was excited to partner with Google to offer Health Connect integration from day one, giving its users a simpler way to consolidate and share their fitness data across applications.

Increased support across devices

Peloton developers wanted to embrace the uniqueness of each device across the Android ecosystem and focus on the individual benefits that their form factors could offer. With this mindset, it was easier for the Peloton team to create a flexible UI that could adapt to various screens.

“We had to stop developing and designing with rigid device categories in mind,” said Ward Bonnefond, a senior staff software engineer at Peloton. “Phones these days no longer have just a single rectangular screen.”

The Peloton team began optimizing for large screens and foldables by improving how the app handles window resizing across orientations and devices. Using resizable emulators, Peloton developers were able to ensure the app behaved as expected with different configurations and screen sizes.

“We used RecyclerViews to determine the number of columns the app displays at runtime based on the available screen size,” said Ward. “We removed restrictions on activity resizing and orientation locking so that our app would function properly in full screen, split screen, resizable floating windows, and foldables.”

Peloton developers used Jetpack WindowManager to support foldable-specific use cases, like tabletop mode for the app’s video player. The window manager library made it easy for developers to place a video above a device’s fold and workout metrics below it.

Peloton developers also streamlined the login process on Android TV. Instead of forcing Members to fumble over typing their credentials with a remote, they can now login through the Peloton App on their phone to quickly connect with their TV.

Quote card with text reads, 'With the Android SDK and Jetpack Libraries, it’s really easy to create a flexible UI that adapts to the different screen size.' — Ward Bonnefond, senior staff software engineer at Peloton

More devices, more opportunities

Since launching the all-new Wear OS application and enhancing support across Android devices, Peloton has seen an uptick in total workouts taken on the Android platform. Although other factors were at play, the Peloton team attributes much of that increase to the new wearable application.

“There are so many different devices with varying capabilities in the Android ecosystem, like phones, watches, tablets, TVs and more,” said Ward. “At the end of the day, we want the Peloton App to be awesome wherever Members use it.”

Get started

Learn how you can start developing for Wear OS and other Android devices today.

Power your Wear OS fitness app with the latest version of Health Services

Posted by Breana Tate, Developer Relations EngineerThe Health Services API enables developers to use on-device sensor data and related algorithms to provide their apps with high-quality data related to activity, exercise, and health. What’s more, you don’t have to choose between conserving battery life and delivering high frequency data–Health Services makes it possible to do both. Since announcing Health Services Alpha at I/O ‘21, we’ve introduced a number of improvements to the platform aimed at simplifying the development experience. Read on to learn about the exciting features from Health Services Beta in Android Jetpack that your app will be able to take advantage of when you migrate from Alpha.

Capture more with new metrics

The Health Services Jetpack Beta introduces new data and exercise types, including DataType.GOLF_SHOT_COUNT, ExerciseType.HORSE_RIDING, and ExerciseType.BACKPACKING. You can review the full list of new exercise and data types here. These supplement the already large library of data and exercise types available to developers building Wear OS apps with Health Services. Additionally, we’ve added the ability to listen for health events, such as fall detection, through PassiveMonitoringClient.

In addition to new data types, we’ve also introduced a new organization model for data in Health Services. This new model makes the Health Services API more type-safe by adding additional classification information to data types and data points, reducing the chance of errors in code. In Beta, all DataPoint types have their own subclass and are derived from the DataPoint class. You can choose from:

  • SampleDataPoints 
  • IntervalDataPoints 
  • StatisticalDataPoints
  • CumulativeDataPoints

DataTypes are categorized as AggregateDataTypes or DeltaDataTypes.

As a result of this change, Health Services can guarantee the correct type at compile time instead of at runtime, reducing errors and improving the developer experience. For example, location data points are now represented as a strongly-typed LocationData object instead of as a DoubleArray. Take a look at the example below:


exerciseUpdate.latestMetrics[DataType.LOCATION]?.forEach {
  val loc = it.value.asDoubleArray()


  println("($lat,$lon,$alt) @ ${it.startDurationFromBoot}")

Health Services Beta:

exerciseUpdate.latestMetrics.getData(DataType.LOCATION).forEach {
  // it.value is of type LocationData
  val loc = it.value
  val time = it.timeDurationFromBoot
  println("loc = [${loc.latitude}, ${loc.longitude}, ${loc.altitude}] @ $time")


As you can see, due to the new approach, Health Services knows that loc is of type List<SampleDataPoint<LocationData>> because DataType.LOCATION is defined as a DeltaDataType<LocationData, SampleDataPoint<LocationData>>.

Consolidated exercise end state

ExerciseState is now included within ExerciseUpdate’s ExerciseStateInfo property. To give you more control over how your app responds to an ending exercise, we’ve added new ExerciseStates called ExerciseState.ENDED and ExerciseState.ENDING to replace what was previously multiple variations of ended and ending states. These new states also include an endReason, such as USER_END, AUTO_END_PREPARE_EXPIRED, and AUTO_END_PERMISSION_LOST.

The following example shows how to check for exercise termination:

val callback = object : ExerciseUpdateCallback {
    override fun onExerciseUpdateReceived(update: ExerciseUpdate) {
        if (update.exerciseStateInfo.state.isEnded) {
            // Workout has either been ended by the user, or otherwise terminated
            val reason = update.exerciseStateInfo.endReason

Improvements to passive monitoring

Health Services Beta also transitions to a new set of passive listener APIs. These changes largely focus on making daily metrics better typed and easier to integrate. For example, we renamed the PassiveListenerConfig function setPassiveGoals to setDailyGoals. This change reinforces that Health Services only supports daily passive goals.We’ve also condensed multiple APIs for registering Passive Listeners into a single registration call. Clients can directly implement the desired overrides for only the data your app needs.

Additionally, the Passive Listener BroadcastReceiver was replaced by the PassiveListenerService, which offers stronger typing, along with better reliability and performance. Clients can now register both a service and a callback simultaneously with different requests, making it easier to register a callback for UI updates while reserving the background request for database updates.

Build for even more devices on Wear OS 3

Health Services is only available for Wear OS 3. The Wear OS 3 ecosystem now includes even more devices, which means your apps can reach even more users. Montblanc, Samsung, and Fossil are just a few of the OEMs that have recently released new devices running Wear OS 3 (with more coming later this year!). The newly released Pixel Watch also features Fitbit health tracking powered by Health Services.

If you haven’t used Health Services before, now is the time to try it out! And if your app is still using Health Services Alpha, here is why you should consider migrating:

  • Ongoing Health Services Development: Since Health Services Beta is the newest version, bug fixes and feature improvements are likely to be prioritized over older versions.
  • Prepares your app infrastructure for when Health Services goes to stable release
  • Improvements to type safety - less chance of error in code!
  • Adds additional functionality to make it easier to work with Health Services data

You can view the full list of changes and updated documentation at developer.android.com.