Energy your Put on OS health app with the most recent model of Well being Companies

Posted by Breana Tate, Developer Relations EngineerThe Well being Companies API permits builders to make use of on-device sensor knowledge and associated algorithms to supply their apps with high-quality knowledge associated to exercise, train, and well being. What’s extra, you don’t have to decide on between conserving battery life and delivering excessive frequency knowledge–Well being Companies makes it attainable to do each. Since asserting Well being Companies Alpha at I/O ‘21, we’ve launched plenty of enhancements to the platform geared toward simplifying the event expertise. Learn on to be taught concerning the thrilling options from Well being Companies Beta in Android Jetpack that your app will have the ability to reap the benefits of if you migrate from Alpha.

Seize extra with new metrics

The Well being Companies Jetpack Beta introduces new knowledge and train sorts, together with DataType.GOLF_SHOT_COUNT, ExerciseType.HORSE_RIDING, and ExerciseType.BACKPACKING. You possibly can evaluate the complete checklist of recent train and knowledge sorts right here. These complement the already giant library of knowledge and train sorts accessible to builders constructing Put on OS apps with Well being Companies. Moreover, we’ve added the flexibility to pay attention for well being occasions, reminiscent of fall detection, via PassiveMonitoringClient.

Along with new knowledge sorts, we’ve additionally launched a brand new group mannequin for knowledge in Well being Companies. This new mannequin makes the Well being Companies API extra type-safe by including extra classification data to knowledge sorts and knowledge factors, decreasing the possibility of errors in code. In Beta, all DataPoint sorts have their very own subclass and are derived from the DataPoint class. You possibly can select from:

  • SampleDataPoints 
  • IntervalDataPoints 
  • StatisticalDataPoints
  • CumulativeDataPoints

DataTypes are categorized as AggregateDataTypes or DeltaDataTypes.

Because of this modification, Well being Companies can assure the proper kind at compile time as an alternative of at runtime, decreasing errors and enhancing the developer expertise. For instance, location knowledge factors at the moment are represented as a strongly-typed LocationData object as an alternative of as a DoubleArray. Check out the instance under:


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


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

Well being Companies Beta:

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


As you’ll be able to see, as a result of new method, Well being Companies is aware of that loc is of kind Listing<SampleDataPoint<LocationData>> as a result of DataType.LOCATION is outlined as a DeltaDataType<LocationData, SampleDataPoint<LocationData>>.

Consolidated train finish state

ExerciseState is now included inside ExerciseUpdate’s ExerciseStateInfo property. To provide you extra management over how your app responds to an ending train, we’ve added new ExerciseStates referred to as ExerciseState.ENDED and ExerciseState.ENDING to exchange what was beforehand a number of variations of ended and ending states. These new states additionally embrace an endReason, reminiscent of USER_END, AUTO_END_PREPARE_EXPIRED, and AUTO_END_PERMISSION_LOST.

The next instance reveals how you can test for train termination:

val callback = object : ExerciseUpdateCallback {
    override enjoyable onExerciseUpdateReceived(replace: ExerciseUpdate) {
        if (replace.exerciseStateInfo.state.isEnded) {
            // Exercise has both been ended by the person, or in any other case terminated
            val motive = replace.exerciseStateInfo.endReason

Enhancements to passive monitoring

Well being Companies Beta additionally transitions to a brand new set of passive listener APIs. These modifications largely give attention to making each day metrics higher typed and simpler to combine. For instance, we renamed the PassiveListenerConfig operate setPassiveGoals to setDailyGoals. This transformation reinforces that Well being Companies solely helps each day passive targets.We’ve additionally condensed a number of APIs for registering Passive Listeners right into a single registration name. Shoppers can instantly implement the specified overrides for under the info your app wants.

Moreover, the Passive Listener BroadcastReceiver was changed by the PassiveListenerService, which presents stronger typing, together with higher reliability and efficiency. Shoppers can now register each a service and a callback concurrently with completely different requests, making it simpler to register a callback for UI updates whereas reserving the background request for database updates.

Construct for much more gadgets on Put on OS 3

Well being Companies is barely accessible for Put on OS 3. The Put on OS 3 ecosystem now contains much more gadgets, which implies your apps can attain much more customers. Montblanc, Samsung, and Fossil are only a few of the OEMs which have just lately launched new gadgets operating Put on OS 3 (with extra coming later this 12 months!). The newly launched Pixel Watch additionally options Fitbit well being monitoring powered by Well being Companies.

When you haven’t used Well being Companies earlier than, now could be the time to attempt it out! And in case your app continues to be utilizing Well being Companies Alpha, right here is why it is best to contemplate migrating:

  • Ongoing Well being Companies Improvement: Since Well being Companies Beta is the most recent model, bug fixes and have enhancements are prone to be prioritized over older variations.
  • Prepares your app infrastructure for when Well being Companies goes to secure launch
  • Enhancements to kind security – much less likelihood of error in code!
  • Provides extra performance to make it simpler to work with Well being Companies knowledge

You possibly can view the complete checklist of modifications and up to date documentation at

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles