Health Connect API
These pages explain how each call behaves. Setting Health Connect up (the dependency, manifest permissions, checking the SDK is available and the first permission request) is covered in the Google Health Connect integration guide. Specific failures, such as a read that returns nothing or a SecurityException, have their own troubleshooting pages. The record types themselves, with their fields and permission strings, are listed in the Health Connect record reference.
Reading records
Raw records one page at a time, and the permissions that decide how far back and when your app may read.
- readRecords and ReadRecordsRequest: paging with pageSize and pageTokenHow Health Connect's readRecords pages results: ReadRecordsRequest defaults, the 1000-record pageSize, and why pageToken can come back as an empty string.UpdatedVerified October 4, 2026
- READ_HEALTH_DATA_HISTORY: reading Health Connect data older than 30 daysHealth Connect reads stop 30 days before your app's first permission grant. What READ_HEALTH_DATA_HISTORY lifts, the feature check and reinstall resets.UpdatedVerified October 4, 2026
- READ_HEALTH_DATA_IN_BACKGROUND: reading Health Connect data from a background workerHow Health Connect background reads work per Google's docs: the READ_HEALTH_DATA_IN_BACKGROUND permission, the feature check and the WorkManager worker.UpdatedVerified October 4, 2026
Totals and buckets
Let Health Connect compute the sum, average or extreme, once for a window or once per minute, hour, day or month.
- aggregate() and AggregateRequest: totals, averages and deduplicated sourcesHow Health Connect's aggregate() works: AggregateRequest, reading AggregationResult, dataOriginFilter, and which data types Google says it deduplicates.UpdatedVerified October 4, 2026
- aggregateGroupByDuration vs aggregateGroupByPeriod: fixed buckets or calendar bucketsDuration buckets are fixed lengths of time; Period buckets follow the calendar. When to use each, the LocalDateTime rule, DST and sparse results.UpdatedVerified October 4, 2026
Keeping up with changes
What was inserted, updated or deleted since your last sync, using a changes token.
Writing and deleting
Upserts keyed on your own ids, the metadata every write must carry, and removing what your app wrote.
- insertRecords and clientRecordId: how Health Connect upsertsHow Health Connect upserts with insertRecords: clientRecordId identifies your record, a higher clientRecordVersion wins, and when to use updateRecords.UpdatedVerified October 4, 2026
- Health Connect Metadata: recordingMethod, Device and the fields Health Connect fills inHealth Connect Metadata per Google's docs: the four RECORDING_METHOD constants, the factory functions, Device types, DataOrigin and lastModifiedTime.UpdatedVerified October 4, 2026
- deleteRecords: deleting Health Connect records by id, client id or time rangeHealth Connect's deleteRecords by record id, client record id or TimeRangeFilter: whose records each form can touch, and why one bad id fails the batch.UpdatedVerified October 4, 2026
Permissions and availability
Requesting, checking and revoking access, the permission screens Google expects, and checking a feature exists before you call it.
- PermissionController: requesting, checking and revoking Health Connect permissionsPermissionController in Health Connect: createRequestPermissionResultContract, getGrantedPermissions, revokeAllPermissions and the rationale activity.UpdatedVerified October 4, 2026
- Health Connect permission UI: Google's guidance for onboarding, requests and settingsGoogle's Health Connect UI guidance, quoted: button labels, asking only for new types, the onboarding activity, settings and permissions cancelled twice.UpdatedVerified October 4, 2026
- HealthConnectFeatures.getFeatureStatus: checking what the user's Health Connect supportsHow getFeatureStatus works in Health Connect, per Google's reference: FEATURE_STATUS_AVAILABLE, all ten FEATURE_ flags, and what to do when one is missing.UpdatedVerified October 4, 2026
Exercise data
GPS routes and the consent they need, and planned sessions for training plans.
- Health Connect exercise routes: ExerciseRouteResult and the per-session consent flowWhy Health Connect returns ExerciseRouteResult.ConsentRequired, how ExerciseRouteRequestContract asks for one route, and the two route permissions.UpdatedVerified October 4, 2026
- PlannedExerciseSessionRecord: training plans in Health ConnectHow Health Connect training plans work per Google's docs: PlannedExerciseSessionRecord, blocks and steps, goals and targets, and linking the session.UpdatedVerified October 4, 2026
Coming from HealthKit
Which Health Connect call does the job of each HealthKit query.
Frequently asked questions
- Which HealthConnectClient method should I use to read health data?
- It depends on the shape of the answer you want. For the records themselves, use readRecords with a ReadRecordsRequest and follow its pageToken. For a total, average, minimum or maximum over one window, use aggregate with an AggregateRequest; Google's read guide says to use it instead of readRecords for cumulative types such as steps, to avoid double counting from multiple sources. For one value per bucket, use aggregateGroupByDuration for fixed lengths of time or aggregateGroupByPeriod for calendar days, weeks or months. To read only what changed since your last sync, including deletions, use getChangesToken and getChanges.
- Are Health Connect writes and deletes transactional?
- Per call, yes. Google's HealthConnectClient reference says insertion of multiple records is executed in a transaction, so if one fails none is inserted; updateRecords is described the same way, and both deleteRecords forms say that if one deletion fails, none is deleted. The transaction covers a single call, so if you split a large batch into several calls, an earlier call that succeeded stays committed when a later one fails.
- Which exceptions can HealthConnectClient methods throw?
- Google's reference lists RemoteException for IPC transport failures, SecurityException for requests with unpermitted access and IOException for disk I/O issues on the read, aggregate, insert, update and delete methods. Google's read guide adds IllegalStateException, thrown when the Health Connect service is not available or the request is not a valid construction, such as a period-bucketed aggregate given an Instant time range. Its paging sample also catches IllegalStateException as a quota error and backs off.
Independent comparison, last reviewed October 4, 2026. Pricing, rate limits, and feature availability change often — confirm current details in each provider’s official documentation before you commit. Product and company names are trademarks of their respective owners; AIFitnessAPI is not affiliated with, endorsed by, or sponsored by any product listed here.