查看 Health Connect 功能
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页介绍了 Health Connect API 的主要功能。
针对记录的 CRUD 操作和数据同步
该平台针对记录的数据提供了标准的插入、更新和删除功能。Health Connect 还包含一项功能,可让客户端应用从 Health Connect 中同步数据。这将生成一个数据更改日志,向开发者和用户显示特定数据类型是否已由其他应用插入或删除。
基本汇总函数
客户端可以对底层数据应用聚合函数,从而提供以下功能:
- 平均值、最小值或最大值(例如活动时段的最低心率和最高心率)。
- 总数(例如每日的总步数)。
- 底层测量次数的简单计数(例如,某一周的活动时段数)。
- 所支持数据类型的总时长(例如,本周深层睡眠时间或今天活动时段的总时长)。
可用性检查
Health Connect 与 Android SDK 版本 28 (Pie) 及更高版本兼容。借助此 SDK,客户端应用可以确定用户的 Android 设备上是否具有 Health Connect API。如果没有,则 Health Connect 会触发可用性检查,以确定用户的设备是否兼容。
权限检查
Health Connect 要求您按应用请求用户授予读取和写入其健康与健身数据的权限。您还可以查看用户已经授予或拒绝了哪些权限。
通过 Health Connect 读取
前台读取
当应用在前台运行时,您通常可以从 Health Connect 读取数据。在这些情况下,您可以考虑使用前台服务来运行此操作,以防用户或系统在读取操作期间将您的应用置于后台。
对于您的应用可能预计中断的情况(例如在应用中显示所读取数据),请直接将数据从 Health Connect 读取至客户端应用。
对于您希望应用在运行时不出现中断的情况,请使用前台服务:
后台读取
您可以请求让应用在后台运行并从 Health Connect 读取数据。如果您请求后台读取权限,用户可以授予您的应用在后台读取数据的权限。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Review Health Connect functionality\n\nThis page describes the main functions of the Health Connect API.\n\nCRUD operations on record and data synchronization\n--------------------------------------------------\n\nThe platform provides standard insert, update, and delete functions for recorded\ndata. Health Connect also includes functionality that allows client apps to\nsynchronize data out of Health Connect. This produces a log of data changes\nthat shows the developer and user whether certain data types have been\ninserted or deleted by other apps.\n\nBasic aggregation functions\n---------------------------\n\nClients can apply an aggregation function over underlying data, providing the\nfollowing:\n\n- The **average, minimum or maximum** values (for example, the minimum and maximum heart rate during an activity session).\n- The **sum total** (for example, the total step count in a daily interval).\n- A **simple count** of the number of underlying measurements (for example, the number of activity sessions in a given week).\n- The **total duration** on supported data types (for example, time spent in deep sleep this week, or total duration of activity sessions today).\n\nAvailability checks\n-------------------\n\nHealth Connect is compatible with Android SDK version 28 (Pie) and higher.\nThe SDK allows client apps to determine whether the Health Connect API is on\nthe user's Android-powered device. If it isn't, Health Connect triggers an\navailability check to determine whether the user's device is compatible.\n\nPermission checks\n-----------------\n\nHealth Connect requires you to request the user's permission to read and\nwrite their health and fitness data on a per-app basis. It also lets you\nsee what permissions have already been granted or denied by the user.\n\nReading with Health Connect\n---------------------------\n\n### Foreground reading\n\nYou can normally read data from Health Connect when your app is\nin the foreground. In these cases, you may consider using a foreground service\nto run this operation in case the user or system places your app\nin the background during a read operation.\n\nFor situations in which your app may expect an interruption, such as displaying\na reading in your application, read directly from Health Connect to your client\napplication.\n\nFor situations in which you prefer your app to run without\ninterruptions, use a\n[foreground service](/develop/background-work/services/fgs):\n\n- [`FOREGROUND_SERVICE_TYPE_HEALTH`](/reference/android/content/pm/ServiceInfo#FOREGROUND_SERVICE_TYPE_HEALTH): Allows app to remain in\n the foreground to collect sensor data, such as a workout app that continues\n to collect data even when the user puts the app in the background.\n\n- [`FOREGROUND_SERVICE_TYPE_SHORT_SERVICE`](/reference/android/content/pm/ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE): A generic-type\n service that allows an app to continue to collect critical data for\n tasks that take less than three minutes,\n even if the user places the app in the background before it completes.\n\n### Background reading\n\nYou can request that your application run in the background and read data from\nHealth Connect. If you request the\n[Background Read](/health-and-fitness/guides/health-connect/develop/read-data#background-read-example)\npermission, your user can grant your app access to read data in the background."]]