Health Connect API
Read and write Android Health Connect records from JavaScript — mirrors the WebViewGold HealthKit API on iOS so one web app covers both platforms.
The Health Connect API reads and writes health records via Android Health Connect. It mirrors the iOS HealthKit functionality of WebViewGold, so you can ship one web app that talks to health data on both platforms. Reads always return today's totals for the requested record type.
Reading a Record:
<a href="readhealthkit://StepsRecord" onclick="setTimeout(show, 300)">
My steps today
</a>
<script>
function show() {
// Injected variable name matches the sanitized record name.
alert(StepsRecord); // e.g. "8421.0 steps"
}
</script>
Writing a Record:
Format: writehealthkit://<RecordName>//<value>
<a href="writehealthkit://StepsRecord//1000">Log 1000 steps</a>
On success the app injects <RecordName> = "WRITE_SUCCESS". On failure it injects the error text.
Supported Records: Any Health Connect record type your app has requested permission for. Common ones:
StepsRecordHeartRateRecordWeightRecordSleepSessionRecordHydrationRecordActiveCaloriesBurnedRecordDistanceRecord
Setup:
- Install Health Connect on the device (pre-installed on Android 14+).
- On first use the app opens the Health Connect permission dialog; the user grants read and/or write for the requested record types.
- If Health Connect is not supported, the injected value falls back to the string
"Health Connect not supported".
Notes: Values are returned as "<number> <unit>" (e.g. "75.4 kg"). Requires Android 8.0 (API 26) or higher.