Integrating Health Connect for Health Data Access in Android

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Integrating Health Connect for Health Data Access in Android
Medium
~3-5 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1050
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Health Connect Integration for Health Data Access in Android

Health Connect — centralized Android health data storage, Google's answer to HealthKit on iOS. Appeared as standalone app in 2022, built-in Android 14 as system component. Correct architecture from start saves weeks on adding new data types or Wear OS support.

Google Play Requirements and Licensing Agreement

Start here — not with code. Apps reading Health Connect data must:

  1. Sign Health Connect Permissions Policy and submit form to Google before publishing
  2. Have privacy policy screen explicitly describing health data usage
  3. Not transfer health data to third parties without explicit user consent (including analytics)
  4. Show justification for each data type when requesting permissions

Violating requirements — guaranteed Play Market removal. Complete Health Connect review before release.

Connection and Permissions

// build.gradle
implementation("androidx.health.connect:connect-client:1.1.0")

Minimum version: minSdk = 26, but Health Connect as app works on Android 9+, built-in — Android 14. On Android 9–13 user must install Health Connect from Play Store.

val healthConnectClient = HealthConnectClient.getOrCreate(context)

// Check availability
when (HealthConnectClient.getSdkStatus(context)) {
    HealthConnectClient.SDK_AVAILABLE -> { /* work */ }
    HealthConnectClient.SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED -> {
        // Show install/update button
        val intent = Intent(Intent.ACTION_VIEW).apply {
            data = Uri.parse("market://details?id=com.google.android.apps.healthdata")
        }
        startActivity(intent)
    }
    HealthConnectClient.SDK_UNAVAILABLE -> { /* Android < 9, not supported */ }
}

Request permissions:

val permissions = setOf(
    HealthPermission.getReadPermission(StepsRecord::class),
    HealthPermission.getReadPermission(HeartRateRecord::class),
    HealthPermission.getWritePermission(ExerciseSessionRecord::class)
)

val requestPermissions = registerForActivityResult(
    PermissionController.createRequestPermissionResultContract()
) { granted ->
    if (granted.containsAll(permissions)) {
        // all permissions granted
    }
}

// Check before requesting
val granted = healthConnectClient.permissionController.getGrantedPermissions()
if (!granted.containsAll(permissions)) {
    requestPermissions.launch(permissions)
}

Reading Data: Records and Queries

Each data type — separate Record class: StepsRecord, HeartRateRecord, SleepSessionRecord, ExerciseSessionRecord etc. Over 40 types.

// Steps for period
val response = healthConnectClient.readRecords(
    ReadRecordsRequest(
        recordType = StepsRecord::class,
        timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
    )
)
val totalSteps = response.records.sumOf { it.count }

For aggregation — aggregateGroupByDuration or aggregateGroupByPeriod:

val aggregateRequest = AggregateGroupByPeriodRequest(
    metrics = setOf(StepsRecord.COUNT_TOTAL),
    timeRangeFilter = TimeRangeFilter.between(startTime, endTime),
    timeRangeSlicer = Period.ofDays(1)
)
val result = healthConnectClient.aggregateGroupByPeriod(aggregateRequest)
result.forEach { bucket ->
    val steps = bucket.result[StepsRecord.COUNT_TOTAL] ?: 0L
    // steps per day
}

Recording Workouts

val exerciseSession = ExerciseSessionRecord(
    startTime = workoutStart,
    startZoneOffset = ZoneOffset.UTC,
    endTime = workoutEnd,
    endZoneOffset = ZoneOffset.UTC,
    exerciseType = ExerciseSessionRecord.EXERCISE_TYPE_RUNNING,
    title = "Morning run"
)

val distanceRecord = DistanceRecord(
    startTime = workoutStart,
    startZoneOffset = ZoneOffset.UTC,
    endTime = workoutEnd,
    endZoneOffset = ZoneOffset.UTC,
    distance = Length.meters(5200.0)
)

healthConnectClient.insertRecords(listOf(exerciseSession, distanceRecord))

Background Reading and Changes

changesToken — incremental updates mechanism, like HKAnchoredObjectQuery in HealthKit:

// Get initial token
val token = healthConnectClient.getChangesToken(
    ChangesTokenRequest(setOf(StepsRecord::class))
)

// On next sync
val changes = healthConnectClient.getChanges(token)
changes.changes.filterIsInstance<UpsertionChange>().forEach { change ->
    // new or updated record
}
val newToken = changes.nextChangesToken // save for next time

Google Fit Compatibility

Health Connect doesn't read Google Fit history automatically. User must manually enable sync in Health Connect settings. If app migrates from Google Fit — notify users old data may display with delay.

Timeframes

Basic Health Connect integration (steps, heart rate, sleep) — 5–8 work days. With workout recording, incremental server sync and Google Fit fallback — 2–3 weeks.