Posted by Breana Tate, Developer Relations EngineerThe Well being Providers API permits builders to make use of on-device sensor information and associated algorithms to supply their apps with high-quality information 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 information–Well being Providers makes it doable to do each. Since saying Well being Providers Alpha at I/O ‘21, we’ve launched numerous enhancements to the platform aimed toward simplifying the event expertise. Learn on to study concerning the thrilling options from Well being Providers Beta in Android Jetpack that your app will be capable to reap the benefits of once you migrate from Alpha.
Seize extra with new metrics
The Well being Providers Jetpack Beta introduces new information and train varieties, together with DataType.GOLF_SHOT_COUNT, ExerciseType.HORSE_RIDING, and ExerciseType.BACKPACKING
. You may evaluation the total listing of recent train and information varieties right here. These complement the already massive library of information and train varieties obtainable to builders constructing Put on OS apps with Well being Providers. Moreover, we’ve added the power to pay attention for well being occasions, reminiscent of fall detection, via PassiveMonitoringClient.
Along with new information varieties, we’ve additionally launched a brand new group mannequin for information in Well being Providers. This new mannequin makes the Well being Providers API extra type-safe by including further classification data to information varieties and information factors, decreasing the prospect of errors in code. In Beta, all DataPoint varieties have their very own subclass and are derived from the DataPoint class. You may select from:
DataTypes are categorized as AggregateDataTypes or DeltaDataTypes.
Because of this modification, Well being Providers can assure the proper kind at compile time as a substitute of at runtime, decreasing errors and enhancing the developer expertise. For instance, location information factors at the moment are represented as a strongly-typed LocationData object as a substitute of as a DoubleArray. Check out the instance under:
Well being Providers Beta:
As you may see, as a result of new strategy, Well being Providers is aware of that loc is of kind Record<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 known as ExerciseState.ENDED and
The next instance exhibits verify for train termination:
Enhancements to passive monitoring
Well being Providers Beta additionally transitions to a brand new set of passive listener APIs. These modifications largely give attention to making every day metrics higher typed and simpler to combine. For instance, we renamed the PassiveListenerConfig operate setPassiveGoals to setDailyGoals. This transformation reinforces that Well being Providers solely helps every day passive targets.We’ve additionally condensed a number of APIs for registering Passive Listeners right into a single registration name. Shoppers can immediately implement the specified overrides for under the information your app wants.
Moreover, the Passive Listener BroadcastReceiver was changed by the PassiveListenerService, which gives stronger typing, together with higher reliability and efficiency. Shoppers can now register each a service and a callback concurrently with totally different requests, making it simpler to register a callback for UI updates whereas reserving the background request for database updates.
Construct for much more units on Put on OS 3
Well being Providers is simply obtainable for Put on OS 3. The Put on OS 3 ecosystem now consists of much more units, which suggests your apps can attain much more customers. Montblanc, Samsung, and Fossil are only a few of the OEMs which have just lately launched new units operating Put on OS 3 (with extra coming later this yr!). The newly launched Pixel Watch additionally options Fitbit well being monitoring powered by Well being Providers.
In case you haven’t used Well being Providers earlier than, now could be the time to attempt it out! And in case your app remains to be utilizing Well being Providers Alpha, right here is why it’s best to think about migrating:
- Ongoing Well being Providers Growth: Since Well being Providers Beta is the most recent model, bug fixes and have enhancements are more likely to be prioritized over older variations.
- Prepares your app infrastructure for when Well being Providers goes to steady launch
- Enhancements to kind security – much less likelihood of error in code!
- Provides further performance to make it simpler to work with Well being Providers information
You may view the total listing of modifications and up to date documentation at developer.android.com.