Read associated data

You can request data that is associated with a specific data.

  • HealthDataStore.readAssociateData()

Samsung Health measures the user’s oxygen saturation and skin temperature during sleep, if the user slept with a wearable device (like Galaxy Watch). Such data is present in the Samsung Health’s Sleep tracker.

After getting a specific sleep data point, reading an associated oxygen saturation data is available as in the following example.

private suspend fun readAssociatedOxygenSaturationData(sleepData: HealthDataPoint) {
    val healthDataStore = HealthDataService.getStore(applicationContext)
    val sleepSessionUid = sleepData.uid
    val readAssociateRequest = DataTypes.SLEEP.associatedReadRequestBuilder
        .setIdFilter(IdFilter.fromDataUid(sleepSessionUid))
        .addAssociatedDataType(DataType.SleepType.Associates.BLOOD_OXYGEN)
        .build()
    val oxygenList = healthDataStore.readAssociatedData(readAssociateRequest).dataList
    for (oxygenData in oxygenList) {
        val oxygenDataPoints = oxygenData.getDataPointOf(DataTypes.BLOOD_OXYGEN)
        oxygenDataPoints?.let {
            for (oxygenPoint in it) {
                val oxygen =     
                    oxygenPoint.getValue(DataType.BloodOxygenType.OXYGEN_SATURATION)
            }
        }
    }
}