Health Connect provides a skin temperature data type to measure peripheral body temperature. This measurement is a particularly useful signal for detecting sleep quality, reproductive health, and the potential onset of illness.
Required permissions
As with any data type in Health Connect, access to skin temperature is protected
by a pair of permissions: READ_SKIN_TEMPERATURE
and
WRITE_SKIN_TEMPERATURE
.
Information included in a skin temperature record
Skin temperature measurements are organized into records. Each record consists of the following information:
- Baseline temperature, in degrees Celsius or degrees Fahrenheit. This is an optional value that is most useful for visualization in your app's UI.
- A list of deltas in skin temperature, each showing the change in skin temperature since the last measurement. If the baseline temperature is provided, these deltas should use the same temperature units.
- The location on the user's body where the measurement was taken: finger, toe, or wrist.
Supported aggregations
Health Connect lets you get the following aggregate values for a given list of deltas:
- Minimum value
- Maximum value
- Average value
Read skin temperature
The following code snippet shows how to read skin temperature measurements using the Jetpack library:
suspend fun readSkinTemperatures() {
// Error handling, permission check, and feature availability check
// aren't included.
// Record includes measurements during the past hour.
val recordEndTime = Instant.now()
val recordStartTime = recordEndTime.minusSeconds(60 * 60)
val response = healthConnectClient.readRecords(
ReadRecordsRequest<SkinTemperatureRecord>(
timeRangeFilter = TimeRangeFilter.between(
recordStartTime, recordEndTime)
)
)
for (skinTemperatureRecord in response.records) {
// Process each skin temperature record here.
}
}
Write skin temperature
The following code snippet shows how to write skin temperature measurements using the Jetpack library:
suspend fun writeSkinTemperatures(): InsertRecordsResponse {
// Error handling, permission check, and feature availability check
// aren't included.
// Record includes measurements during the past hour.
val recordEndTime: ZonedDateTime = now()
val recordStartTime: ZonedDateTime = recordEndTime.minusHours(1)
return healthConnectClient.insertRecords(
// For this example, there's only one skin temperature record.
listOf(
SkinTemperatureRecord(
startTime = recordStartTime.toInstant(),
startZoneOffset = recordStartTime.offset,
endTime = recordEndTime.toInstant(),
endZoneOffset = recordEndTime.offset,
deltas = listOf(
SkinTemperatureRecord.Delta(
recordEndTime.minusMinutes(50), celsius(0.5)),
SkinTemperatureRecord.Delta(
recordEndTime.minusMinutes(30), celsius(-0.7))
),
measurementLocation =
SkinTemperatureRecord.MEASUREMENT_LOCATION_FINGER
)
)
)
}