@devmaxime/capacitor-health-connect

中文文档
1.1.0发布于 2025/10/27MITTypeScriptESM + CJS零依赖近 30 天下载 4311

Capacitor plugin to interact with Health Connect

原始使用文档
文档目录12 节
  1. Install
  2. Permissions
  3. API
  4. checkAvailability()
  5. requestPermissions(...)
  6. getGrantedPermissions()
  7. revokePermissions()
  8. readRecords(...)
  9. aggregateRecords(...)
  10. Interfaces
  11. Type Aliases
  12. Available records in Android Health Connect TODO: add this …

Capacitor plugin to interact with Android Health Connect.

Install

npm install @devmaxime/capacitor-health-connect
npx cap sync

Add the following to your app's AndroidManifest.xml:

<queries>
   <package android:name="com.google.android.apps.healthdata" />
</queries>

Also add this to your AndroidManifest.xml:

<application>
...
    <activity>
    ...

        <!-- Permission handling for Android 13 and before -->
        <intent-filter>
            <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
        </intent-filter>

        <!-- Permission handling for Android 14 and later -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW_PERMISSION_USAGE"/>
            <category android:name="android.intent.category.HEALTH_PERMISSIONS"/>
        </intent-filter>

    ...
    </activity>
</application>

Permissions

You also need to add permissions for the records you want to read and/or write to the AndroidManifest.xml. A complete list of available records and the corresponding permissions can be found here.

<!-- Example permissions -->
<uses-permission android:name="android.permission.health.READ_STEPS"/>
<uses-permission android:name="android.permission.health.WRITE_STEPS"/>
<uses-permission android:name="android.permission.health.READ_EXERCISE"/>
<uses-permission android:name="android.permission.health.WRITE_EXERCISE"/>

API

checkAvailability()

checkAvailability() => Promise<{ availability: HealthConnectAvailability; }>

Returns: Promise<{ availability: HealthConnectAvailability; }>


requestPermissions(...)

requestPermissions(options: { read: RecordType[]; write: RecordType[]; }) => Promise<PermissionsResponse>
ParamType
options{ read: RecordType[]; write: RecordType[]; }

Returns: Promise<PermissionsResponse>


getGrantedPermissions()

getGrantedPermissions() => Promise<PermissionsResponse>

Returns: Promise<PermissionsResponse>


revokePermissions()

revokePermissions() => Promise<void>

readRecords(...)

readRecords(options: { start: string; end: string; type: RecordType; pageSize?: number; pageToken?: string; }) => Promise<ReadRecordsResponse>

Reads records of the specified type within a time range.

When pageToken is not provided, automatic pagination is used to retrieve ALL records within the specified time range. This may take longer for large datasets but ensures complete data retrieval.

When pageToken is provided, manual pagination is used and only a single page of results is returned along with a nextPageToken for retrieving subsequent pages.

ParamType
options{ start: string; end: string; type: RecordType; pageSize?: number; pageToken?: string; }

Returns: Promise<ReadRecordsResponse>


aggregateRecords(...)

aggregateRecords(options: { start: string; end: string; type: AggregateRecordType; groupBy?: AggregateGroupBy; }) => Promise<AggregateResponse>

Aggregates records of the specified type within a time range. Returns aggregated data grouped by the specified time period (e.g., daily totals).

ParamType
options{ start: string; end: string; type: AggregateRecordType; groupBy?: AggregateGroupBy; }

Returns: Promise<AggregateResponse>


Interfaces

PermissionsResponse

PropType
readRecordType[]
writeRecordType[]

ReadRecordsResponse

Response from reading health records.

When using automatic pagination (no pageToken provided), all records are returned and nextPageToken will be undefined.

When using manual pagination (pageToken provided), nextPageToken will contain the token for the next page, or undefined if this is the last page.

PropType
recordsany[]
nextPageTokenstring

AggregateResponse

Response from aggregating health records. Contains aggregated data grouped by time periods.

PropType
aggregatesAggregateData[]

AggregateData

Aggregated data for a specific time period.

PropType
startTimestring
endTimestring
valuenumber
unitstring

Type Aliases

HealthConnectAvailability

'Available' | 'NotSupported' | 'NotInstalled'

RecordType

'Steps' | 'Weight' | 'ActivitySession' | 'SleepSession' | 'RestingHeartRate'

AggregateRecordType

'Steps' | 'Distance' | 'TotalCaloriesBurned' | 'ActiveCaloriesBurned' | 'HeartRate'

AggregateGroupBy

'day' | 'hour' | 'week' | 'month'

Available records in Android Health Connect TODO: add this to the docs.

ActiveCaloriesBurned -> class androidx.health.connect.client.records.ActiveCaloriesBurnedRecord ActivitySession -> class androidx.health.connect.client.records.ExerciseSessionRecord BasalBodyTemperature -> class androidx.health.connect.client.records.BasalBodyTemperatureRecord BasalMetabolicRate -> class androidx.health.connect.client.records.BasalMetabolicRateRecord BloodGlucose -> class androidx.health.connect.client.records.BloodGlucoseRecord BloodPressure -> class androidx.health.connect.client.records.BloodPressureRecord BodyFat -> class androidx.health.connect.client.records.BodyFatRecord BodyTemperature -> class androidx.health.connect.client.records.BodyTemperatureRecord BodyWaterMass -> class androidx.health.connect.client.records.BodyWaterMassRecord BoneMass -> class androidx.health.connect.client.records.BoneMassRecord CervicalMucus -> class androidx.health.connect.client.records.CervicalMucusRecord CyclingPedalingCadenceSeries -> class androidx.health.connect.client.records.CyclingPedalingCadenceRecord Distance -> class androidx.health.connect.client.records.DistanceRecord ElevationGained -> class androidx.health.connect.client.records.ElevationGainedRecord FloorsClimbed -> class androidx.health.connect.client.records.FloorsClimbedRecord HeartRateSeries -> class androidx.health.connect.client.records.HeartRateRecord HeartRateVariabilityRmssd -> class androidx.health.connect.client.records.HeartRateVariabilityRmssdRecord Height -> class androidx.health.connect.client.records.HeightRecord Hydration -> class androidx.health.connect.client.records.HydrationRecord LeanBodyMass -> class androidx.health.connect.client.records.LeanBodyMassRecord Menstruation -> class androidx.health.connect.client.records.MenstruationFlowRecord MenstruationPeriod -> class androidx.health.connect.client.records.MenstruationPeriodRecord Nutrition -> class androidx.health.connect.client.records.NutritionRecord OvulationTest -> class androidx.health.connect.client.records.OvulationTestRecord OxygenSaturation -> class androidx.health.connect.client.records.OxygenSaturationRecord PowerSeries -> class androidx.health.connect.client.records.PowerRecord RespiratoryRate -> class androidx.health.connect.client.records.RespiratoryRateRecord RestingHeartRate -> class androidx.health.connect.client.records.RestingHeartRateRecord SexualActivity -> class androidx.health.connect.client.records.SexualActivityRecord SkinTemperature -> class androidx.health.connect.client.records.SkinTemperatureRecord SleepSession -> class androidx.health.connect.client.records.SleepSessionRecord SpeedSeries -> class androidx.health.connect.client.records.SpeedRecord IntermenstrualBleeding -> class androidx.health.connect.client.records.IntermenstrualBleedingRecord Steps -> class androidx.health.connect.client.records.StepsRecord StepsCadenceSeries -> class androidx.health.connect.client.records.StepsCadenceRecord TotalCaloriesBurned -> class androidx.health.connect.client.records.TotalCaloriesBurnedRecord Vo2Max -> class androidx.health.connect.client.records.Vo2MaxRecord WheelchairPushes -> class androidx.health.connect.client.records.WheelchairPushesRecord Weight -> class androidx.health.connect.client.records.WeightRecord

Initially forked from @sprintwerk/capacitor-android-health-connect

版本与发布记录

@devmaxime/capacitor-health-connect 共发布 4 个版本,首次发布于 2025/09/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.0latest2025/10/271 年前
1.0.22025/09/271.1 年前
1.0.12025/09/271.1 年前
1.0.02025/09/271.1 年前

关于 @devmaxime/capacitor-health-connect 的常见问题

@devmaxime/capacitor-health-connect 是什么?

Capacitor plugin to interact with Health Connect

如何安装 @devmaxime/capacitor-health-connect?

在项目目录运行 npm install @devmaxime/capacitor-health-connect,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=7.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@devmaxime/capacitor-health-connect 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@devmaxime/capacitor-health-connect 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@devmaxime/capacitor-health-connect 可以商用吗?

@devmaxime/capacitor-health-connect 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@devmaxime/capacitor-health-connect 的下载量有多少?

根据 npm 官方下载统计,@devmaxime/capacitor-health-connect 在 2026/10/12 – 2026/11/10 这 30 天内被下载 4,311 次,日均约 144 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@devmaxime/capacitor-health-connect 还在维护吗?

最新版本 1.1.0 发布于 2025/10/27(1 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/09/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。