readAssociatedDataAsync

Reads asynchronously a set of associated data for a certain target data according to the given request.

For example, measured sleep data is a base data type, and blood oxygen level and skin temperature data are associated data types. The code snippet below shows how to get associated data for a specific SleepType data record .

val readRequest = DataTypes.SLEEP.readDataRequestBuilder
    .setLocalTimeFilter(localTimeFilter).build()
val result = healthDataStore.readDataAsync(readRequest).get()
result.dataList.forEach { sleepDataPoint ->
    val sleepId = sleepDataPoint.uid
    val idFilter = IdFilter.fromDataUid(sleepId)
    val request = DataTypes.SLEEP.associatedReadRequestBuilder
        .addAssociatedDataType(DataType.SleepType.Associates.BLOOD_OXYGEN)
        .addAssociatedDataType(DataType.SleepType.Associates.SKIN_TEMPERATURE)
        .setIdFilter(idFilter)
        .build()

    val associatedResult = healthDataStore.readAssociatedDataAsync(request).get()
    associatedResult.dataList.forEach { associatedDataPoints->
        val oxygenDataPoints = associatedDataPoints.getDataPointOf(DataTypes.BLOOD_OXYGEN)
        oxygenDataPoints?.forEach{
            val oxygenSaturation = it.getValue(DataType.BloodOxygenType.OXYGEN_SATURATION)
            // This processes the oxygen saturation value.
        }

        val skinTemperatureDataPoints = associatedDataPoints.getDataPointOf(DataTypes.SKIN_TEMPERATURE)
        skinTemperatureDataPoints?.forEach {
            val skinTemperature = it.getValue(DataType.SkinTemperatureType.SKIN_TEMPERATURE)
            // This processes the skin temperature value.
        }
    }
}

Return

The AsyncSingleFuture instance that returns the AssociatedDataPoints data set.

Since

1.0.0

Parameters

request

A ReadDataRequest instance to specify the read conditions.

Preferences Submitted

You have successfully updated your cookie preferences.