@asiriindatissa/capacitor-health 8.4.0 → 8.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -20
- package/android/src/main/java/app/capgo/plugin/health/HealthDataType.kt +2 -0
- package/android/src/main/java/app/capgo/plugin/health/HealthManager.kt +53 -16
- package/dist/docs.json +5 -1
- package/dist/esm/definitions.d.ts +2 -2
- package/dist/esm/definitions.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ if (!availability.available) {
|
|
|
97
97
|
// Ask for separate read/write access scopes
|
|
98
98
|
// Include 'workouts' if you need to query workout sessions
|
|
99
99
|
await Health.requestAuthorization({
|
|
100
|
-
read: ['steps', 'heartRate', 'weight', 'workouts'],
|
|
100
|
+
read: ['steps', 'heartRate', 'weight', 'totalCalories', 'workouts'],
|
|
101
101
|
write: ['weight'],
|
|
102
102
|
});
|
|
103
103
|
|
|
@@ -118,14 +118,15 @@ await Health.saveSample({
|
|
|
118
118
|
|
|
119
119
|
### Supported data types
|
|
120
120
|
|
|
121
|
-
| Identifier
|
|
122
|
-
|
|
|
123
|
-
| `steps`
|
|
124
|
-
| `distance`
|
|
125
|
-
| `calories`
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
121
|
+
| Identifier | Default unit | Notes |
|
|
122
|
+
| --------------- | ------------- | -------------------------- |
|
|
123
|
+
| `steps` | `count` | Step count deltas |
|
|
124
|
+
| `distance` | `meter` | Walking / running distance |
|
|
125
|
+
| `calories` | `kilocalorie` | Active energy burned |
|
|
126
|
+
| `totalCalories` | `kilocalorie` | Total energy burned |
|
|
127
|
+
| `heartRate` | `bpm` | Beats per minute |
|
|
128
|
+
| `weight` | `kilogram` | Body mass |
|
|
129
|
+
| `height` | `meter` | Body height |
|
|
129
130
|
|
|
130
131
|
All write operations expect the default unit shown above. On Android the `metadata` option is currently ignored by Health Connect.
|
|
131
132
|
|
|
@@ -135,8 +136,10 @@ To query workout sessions, you need to request read permission for `'workouts'`:
|
|
|
135
136
|
|
|
136
137
|
```ts
|
|
137
138
|
// Request permission to read workouts
|
|
139
|
+
// IMPORTANT: To see totalEnergyBurned and totalDistance in workout data,
|
|
140
|
+
// you MUST also request permissions for 'calories' (or 'totalCalories') and 'distance'
|
|
138
141
|
await Health.requestAuthorization({
|
|
139
|
-
read: ['workouts', '
|
|
142
|
+
read: ['workouts', 'calories', 'totalCalories', 'distance'], // Include data types for workout metrics
|
|
140
143
|
write: [],
|
|
141
144
|
});
|
|
142
145
|
|
|
@@ -146,9 +149,18 @@ const { workouts } = await Health.queryWorkouts({
|
|
|
146
149
|
endDate: new Date().toISOString(),
|
|
147
150
|
limit: 10,
|
|
148
151
|
});
|
|
152
|
+
|
|
153
|
+
// Each workout may include:
|
|
154
|
+
// - workoutType, duration, startDate, endDate (always present)
|
|
155
|
+
// - totalEnergyBurned (if calories/totalCalories permission granted and data exists)
|
|
156
|
+
// - totalDistance (if distance permission granted and data exists)
|
|
149
157
|
```
|
|
150
158
|
|
|
151
|
-
Note
|
|
159
|
+
**Note:**
|
|
160
|
+
|
|
161
|
+
- `'workouts'` is a special read-only permission type. You cannot write workouts with this plugin.
|
|
162
|
+
- Workout energy and distance data are aggregated from separate Health Connect records during the workout time period. If you don't request permissions for `calories`/`totalCalories` and `distance`, these fields will be missing from workout results.
|
|
163
|
+
- If `totalEnergyBurned` or `totalDistance` are missing despite having permissions, it means no calorie or distance data was recorded during that workout period in Health Connect.
|
|
152
164
|
|
|
153
165
|
## API
|
|
154
166
|
|
|
@@ -375,14 +387,14 @@ Queries workout sessions from the native health store on Android (Health Connect
|
|
|
375
387
|
|
|
376
388
|
#### WriteSampleOptions
|
|
377
389
|
|
|
378
|
-
| Prop | Type | Description
|
|
379
|
-
| --------------- | --------------------------------------------------------------- |
|
|
380
|
-
| **`dataType`** | <code><a href="#healthdatatype">HealthDataType</a></code> |
|
|
381
|
-
| **`value`** | <code>number</code> |
|
|
382
|
-
| **`unit`** | <code><a href="#healthunit">HealthUnit</a></code> | Optional unit override. If omitted, the default unit for the data type is used (count for `steps`, meter for `distance`, kilocalorie for `calories`, bpm for `heartRate`, kilogram for `weight`, meter for `height`). |
|
|
383
|
-
| **`startDate`** | <code>string</code> | ISO 8601 start date for the sample. Defaults to now.
|
|
384
|
-
| **`endDate`** | <code>string</code> | ISO 8601 end date for the sample. Defaults to startDate.
|
|
385
|
-
| **`metadata`** | <code><a href="#record">Record</a><string, string></code> | Metadata key-value pairs forwarded to the native APIs where supported.
|
|
390
|
+
| Prop | Type | Description |
|
|
391
|
+
| --------------- | --------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
392
|
+
| **`dataType`** | <code><a href="#healthdatatype">HealthDataType</a></code> | |
|
|
393
|
+
| **`value`** | <code>number</code> | |
|
|
394
|
+
| **`unit`** | <code><a href="#healthunit">HealthUnit</a></code> | Optional unit override. If omitted, the default unit for the data type is used (count for `steps`, meter for `distance`, kilocalorie for `calories` and `totalCalories`, bpm for `heartRate`, kilogram for `weight`, meter for `height`). |
|
|
395
|
+
| **`startDate`** | <code>string</code> | ISO 8601 start date for the sample. Defaults to now. |
|
|
396
|
+
| **`endDate`** | <code>string</code> | ISO 8601 end date for the sample. Defaults to startDate. |
|
|
397
|
+
| **`metadata`** | <code><a href="#record">Record</a><string, string></code> | Metadata key-value pairs forwarded to the native APIs where supported. |
|
|
386
398
|
|
|
387
399
|
|
|
388
400
|
#### QueryWorkoutsResult
|
|
@@ -431,7 +443,7 @@ Includes 'workouts' for querying workout sessions via queryWorkouts().
|
|
|
431
443
|
|
|
432
444
|
#### HealthDataType
|
|
433
445
|
|
|
434
|
-
<code>'steps' | 'distance' | 'calories' | 'heartRate' | 'weight' | 'height'</code>
|
|
446
|
+
<code>'steps' | 'distance' | 'calories' | 'totalCalories' | 'heartRate' | 'weight' | 'height'</code>
|
|
435
447
|
|
|
436
448
|
|
|
437
449
|
#### HealthUnit
|
|
@@ -7,6 +7,7 @@ import androidx.health.connect.client.records.HeartRateRecord
|
|
|
7
7
|
import androidx.health.connect.client.records.HeightRecord
|
|
8
8
|
import androidx.health.connect.client.records.Record
|
|
9
9
|
import androidx.health.connect.client.records.StepsRecord
|
|
10
|
+
import androidx.health.connect.client.records.TotalCaloriesBurnedRecord
|
|
10
11
|
import androidx.health.connect.client.records.WeightRecord
|
|
11
12
|
import kotlin.reflect.KClass
|
|
12
13
|
|
|
@@ -18,6 +19,7 @@ enum class HealthDataType(
|
|
|
18
19
|
STEPS("steps", StepsRecord::class, "count"),
|
|
19
20
|
DISTANCE("distance", DistanceRecord::class, "meter"),
|
|
20
21
|
CALORIES("calories", ActiveCaloriesBurnedRecord::class, "kilocalorie"),
|
|
22
|
+
TOTAL_CALORIES("totalCalories", TotalCaloriesBurnedRecord::class, "kilocalorie"),
|
|
21
23
|
HEART_RATE("heartRate", HeartRateRecord::class, "bpm"),
|
|
22
24
|
WEIGHT("weight", WeightRecord::class, "kilogram"),
|
|
23
25
|
HEIGHT("height", HeightRecord::class, "meter");
|
|
@@ -127,6 +127,16 @@ class HealthManager {
|
|
|
127
127
|
)
|
|
128
128
|
samples.add(record.startTime to payload)
|
|
129
129
|
}
|
|
130
|
+
HealthDataType.TOTAL_CALORIES -> readRecords(client, TotalCaloriesBurnedRecord::class, startTime, endTime, limit) { record ->
|
|
131
|
+
val payload = createSamplePayload(
|
|
132
|
+
dataType,
|
|
133
|
+
record.startTime,
|
|
134
|
+
record.endTime,
|
|
135
|
+
record.energy.inKilocalories,
|
|
136
|
+
record.metadata
|
|
137
|
+
)
|
|
138
|
+
samples.add(record.startTime to payload)
|
|
139
|
+
}
|
|
130
140
|
HealthDataType.WEIGHT -> readRecords(client, WeightRecord::class, startTime, endTime, limit) { record ->
|
|
131
141
|
val payload = createSamplePayload(
|
|
132
142
|
dataType,
|
|
@@ -238,6 +248,16 @@ class HealthManager {
|
|
|
238
248
|
)
|
|
239
249
|
client.insertRecords(listOf(record))
|
|
240
250
|
}
|
|
251
|
+
HealthDataType.TOTAL_CALORIES -> {
|
|
252
|
+
val record = TotalCaloriesBurnedRecord(
|
|
253
|
+
startTime = startTime,
|
|
254
|
+
startZoneOffset = zoneOffset(startTime),
|
|
255
|
+
endTime = endTime,
|
|
256
|
+
endZoneOffset = zoneOffset(endTime),
|
|
257
|
+
energy = Energy.kilocalories(value)
|
|
258
|
+
)
|
|
259
|
+
client.insertRecords(listOf(record))
|
|
260
|
+
}
|
|
241
261
|
HealthDataType.WEIGHT -> {
|
|
242
262
|
val record = WeightRecord(
|
|
243
263
|
time = startTime,
|
|
@@ -380,9 +400,13 @@ class HealthManager {
|
|
|
380
400
|
// Removed dataOriginFilter to get distance from all sources during workout time
|
|
381
401
|
)
|
|
382
402
|
val result = client.aggregate(aggregateRequest)
|
|
383
|
-
result[DistanceRecord.DISTANCE_TOTAL]?.inMeters
|
|
403
|
+
val distance = result[DistanceRecord.DISTANCE_TOTAL]?.inMeters
|
|
404
|
+
if (distance == null) {
|
|
405
|
+
android.util.Log.d("HealthManager", "No distance data found for workout ${session.startTime} to ${session.endTime}")
|
|
406
|
+
}
|
|
407
|
+
distance
|
|
384
408
|
} catch (e: Exception) {
|
|
385
|
-
android.util.Log.
|
|
409
|
+
android.util.Log.w("HealthManager", "Distance aggregation failed for workout: ${e.message}", e)
|
|
386
410
|
null // Permission might not be granted or no data available
|
|
387
411
|
}
|
|
388
412
|
|
|
@@ -393,21 +417,34 @@ class HealthManager {
|
|
|
393
417
|
timeRangeFilter = timeRange
|
|
394
418
|
)
|
|
395
419
|
val result = client.aggregate(aggregateRequest)
|
|
396
|
-
result[ActiveCaloriesBurnedRecord.ACTIVE_CALORIES_TOTAL]?.inKilocalories
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
420
|
+
val activeCalories = result[ActiveCaloriesBurnedRecord.ACTIVE_CALORIES_TOTAL]?.inKilocalories
|
|
421
|
+
if (activeCalories != null && activeCalories > 0) {
|
|
422
|
+
android.util.Log.d("HealthManager", "Found active calories: $activeCalories kcal")
|
|
423
|
+
activeCalories
|
|
424
|
+
} else {
|
|
425
|
+
android.util.Log.d("HealthManager", "No active calories found, trying total calories")
|
|
426
|
+
// Fall back to total calories
|
|
427
|
+
try {
|
|
428
|
+
val totalRequest = AggregateRequest(
|
|
429
|
+
metrics = setOf(TotalCaloriesBurnedRecord.ENERGY_TOTAL),
|
|
430
|
+
timeRangeFilter = timeRange
|
|
431
|
+
)
|
|
432
|
+
val totalResult = client.aggregate(totalRequest)
|
|
433
|
+
val totalCalories = totalResult[TotalCaloriesBurnedRecord.ENERGY_TOTAL]?.inKilocalories
|
|
434
|
+
if (totalCalories != null && totalCalories > 0) {
|
|
435
|
+
android.util.Log.d("HealthManager", "Found total calories: $totalCalories kcal")
|
|
436
|
+
} else {
|
|
437
|
+
android.util.Log.w("HealthManager", "No calorie data (active or total) available for workout ${session.startTime} to ${session.endTime}")
|
|
438
|
+
}
|
|
439
|
+
totalCalories
|
|
440
|
+
} catch (e2: Exception) {
|
|
441
|
+
android.util.Log.w("HealthManager", "Total calories aggregation failed: ${e2.message}", e2)
|
|
442
|
+
null
|
|
443
|
+
}
|
|
410
444
|
}
|
|
445
|
+
} catch (e: Exception) {
|
|
446
|
+
android.util.Log.w("HealthManager", "Active calories aggregation failed: ${e.message}", e)
|
|
447
|
+
null // Permission might not be granted or no data available
|
|
411
448
|
}
|
|
412
449
|
|
|
413
450
|
return WorkoutAggregatedData(
|
package/dist/docs.json
CHANGED
|
@@ -431,7 +431,7 @@
|
|
|
431
431
|
{
|
|
432
432
|
"name": "unit",
|
|
433
433
|
"tags": [],
|
|
434
|
-
"docs": "Optional unit override. If omitted, the default unit for the data type is used\n(count for `steps`, meter for `distance`, kilocalorie for `calories`, bpm for `heartRate`, kilogram for `weight`, meter for `height`).",
|
|
434
|
+
"docs": "Optional unit override. If omitted, the default unit for the data type is used\n(count for `steps`, meter for `distance`, kilocalorie for `calories` and `totalCalories`, bpm for `heartRate`, kilogram for `weight`, meter for `height`).",
|
|
435
435
|
"complexTypes": [
|
|
436
436
|
"HealthUnit"
|
|
437
437
|
],
|
|
@@ -639,6 +639,10 @@
|
|
|
639
639
|
"text": "'calories'",
|
|
640
640
|
"complexTypes": []
|
|
641
641
|
},
|
|
642
|
+
{
|
|
643
|
+
"text": "'totalCalories'",
|
|
644
|
+
"complexTypes": []
|
|
645
|
+
},
|
|
642
646
|
{
|
|
643
647
|
"text": "'heartRate'",
|
|
644
648
|
"complexTypes": []
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type HealthDataType = 'steps' | 'distance' | 'calories' | 'heartRate' | 'weight' | 'height';
|
|
1
|
+
export type HealthDataType = 'steps' | 'distance' | 'calories' | 'totalCalories' | 'heartRate' | 'weight' | 'height';
|
|
2
2
|
export type HealthUnit = 'count' | 'meter' | 'kilocalorie' | 'bpm' | 'kilogram';
|
|
3
3
|
/**
|
|
4
4
|
* Data types that can be requested for read authorization.
|
|
@@ -95,7 +95,7 @@ export interface WriteSampleOptions {
|
|
|
95
95
|
value: number;
|
|
96
96
|
/**
|
|
97
97
|
* Optional unit override. If omitted, the default unit for the data type is used
|
|
98
|
-
* (count for `steps`, meter for `distance`, kilocalorie for `calories`, bpm for `heartRate`, kilogram for `weight`, meter for `height`).
|
|
98
|
+
* (count for `steps`, meter for `distance`, kilocalorie for `calories` and `totalCalories`, bpm for `heartRate`, kilogram for `weight`, meter for `height`).
|
|
99
99
|
*/
|
|
100
100
|
unit?: HealthUnit;
|
|
101
101
|
/** ISO 8601 start date for the sample. Defaults to now. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export type HealthDataType = 'steps' | 'distance' | 'calories' | 'heartRate' | 'weight' | 'height';\n\nexport type HealthUnit = 'count' | 'meter' | 'kilocalorie' | 'bpm' | 'kilogram';\n\n/**\n * Data types that can be requested for read authorization.\n * Includes 'workouts' for querying workout sessions via queryWorkouts().\n */\nexport type ReadAuthorizationType = HealthDataType | 'workouts';\n\nexport interface AuthorizationOptions {\n /**\n * Data types that should be readable after authorization.\n * Include 'workouts' to enable queryWorkouts() method.\n */\n read?: ReadAuthorizationType[];\n /** Data types that should be writable after authorization. */\n write?: HealthDataType[];\n}\n\nexport interface AuthorizationStatus {\n /** Data types (and 'workouts') that are authorized for reading */\n readAuthorized: ReadAuthorizationType[];\n /** Data types (and 'workouts') that are denied for reading */\n readDenied: ReadAuthorizationType[];\n /** Data types that are authorized for writing */\n writeAuthorized: HealthDataType[];\n /** Data types that are denied for writing */\n writeDenied: HealthDataType[];\n}\n\nexport interface AvailabilityResult {\n available: boolean;\n /** Platform specific details (for debugging/diagnostics). */\n platform?: 'android' | 'web';\n reason?: string;\n}\n\nexport interface QueryOptions {\n /** The type of data to retrieve from the health store. */\n dataType: HealthDataType;\n /** Inclusive ISO 8601 start date (defaults to now - 1 day). */\n startDate?: string;\n /** Exclusive ISO 8601 end date (defaults to now). */\n endDate?: string;\n /** Maximum number of samples to return (defaults to 100). */\n limit?: number;\n /** Return results sorted ascending by start date (defaults to false). */\n ascending?: boolean;\n}\n\nexport interface HealthSample {\n dataType: HealthDataType;\n value: number;\n unit: HealthUnit;\n startDate: string;\n endDate: string;\n sourceName?: string;\n sourceId?: string;\n}\n\nexport interface ReadSamplesResult {\n samples: HealthSample[];\n}\n\nexport type WorkoutType =\n | 'running'\n | 'cycling'\n | 'walking'\n | 'swimming'\n | 'yoga'\n | 'strengthTraining'\n | 'hiking'\n | 'tennis'\n | 'basketball'\n | 'soccer'\n | 'americanFootball'\n | 'baseball'\n | 'crossTraining'\n | 'elliptical'\n | 'rowing'\n | 'stairClimbing'\n | 'traditionalStrengthTraining'\n | 'waterFitness'\n | 'waterPolo'\n | 'waterSports'\n | 'wrestling'\n | 'other';\n\nexport interface QueryWorkoutsOptions {\n /** Optional workout type filter. If omitted, all workout types are returned. */\n workoutType?: WorkoutType;\n /** Inclusive ISO 8601 start date (defaults to now - 1 day). */\n startDate?: string;\n /** Exclusive ISO 8601 end date (defaults to now). */\n endDate?: string;\n /** Maximum number of workouts to return (defaults to 100). */\n limit?: number;\n /** Return results sorted ascending by start date (defaults to false). */\n ascending?: boolean;\n}\n\nexport interface Workout {\n /** The type of workout. */\n workoutType: WorkoutType;\n /** Duration of the workout in seconds. */\n duration: number;\n /** Total energy burned in kilocalories (if available). */\n totalEnergyBurned?: number;\n /** Total distance in meters (if available). */\n totalDistance?: number;\n /** ISO 8601 start date of the workout. */\n startDate: string;\n /** ISO 8601 end date of the workout. */\n endDate: string;\n /** Source name that recorded the workout. */\n sourceName?: string;\n /** Source bundle identifier. */\n sourceId?: string;\n /** Additional metadata (if available). */\n metadata?: Record<string, string>;\n}\n\nexport interface QueryWorkoutsResult {\n workouts: Workout[];\n}\n\nexport interface WriteSampleOptions {\n dataType: HealthDataType;\n value: number;\n /**\n * Optional unit override. If omitted, the default unit for the data type is used\n * (count for `steps`, meter for `distance`, kilocalorie for `calories`, bpm for `heartRate`, kilogram for `weight`, meter for `height`).\n */\n unit?: HealthUnit;\n /** ISO 8601 start date for the sample. Defaults to now. */\n startDate?: string;\n /** ISO 8601 end date for the sample. Defaults to startDate. */\n endDate?: string;\n /** Metadata key-value pairs forwarded to the native APIs where supported. */\n metadata?: Record<string, string>;\n}\n\nexport interface HealthPlugin {\n /** Returns whether the current platform supports the native health SDK. */\n isAvailable(): Promise<AvailabilityResult>;\n /** Requests read/write access to the provided data types. */\n requestAuthorization(options: AuthorizationOptions): Promise<AuthorizationStatus>;\n /** Checks authorization status for the provided data types without prompting the user. */\n checkAuthorization(options: AuthorizationOptions): Promise<AuthorizationStatus>;\n /** Reads samples for the given data type within the specified time frame. */\n readSamples(options: QueryOptions): Promise<ReadSamplesResult>;\n /** Writes a single sample to the native health store. */\n saveSample(options: WriteSampleOptions): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ version: string }>} a Promise with version for this device\n * @throws An error if something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n\n /**\n * Opens the Health Connect settings screen.\n *\n * Use this to direct users to manage their Health Connect permissions\n * or to install Health Connect if not available.\n *\n * @throws An error if Health Connect settings cannot be opened\n */\n openHealthConnectSettings(): Promise<void>;\n\n /**\n * Shows the app's privacy policy for Health Connect.\n *\n * This displays the same privacy policy screen that Health Connect shows\n * when the user taps \"Privacy policy\" in the permissions dialog.\n *\n * The privacy policy URL can be configured by adding a string resource\n * named \"health_connect_privacy_policy_url\" in your app's strings.xml,\n * or by placing an HTML file at www/privacypolicy.html in your assets.\n *\n * @throws An error if the privacy policy cannot be displayed\n */\n showPrivacyPolicy(): Promise<void>;\n\n /**\n * Queries workout sessions from the native health store on Android (Health Connect).\n *\n * @param options Query options including optional workout type filter, date range, limit, and sort order\n * @returns A promise that resolves with the workout sessions\n * @throws An error if something went wrong\n */\n queryWorkouts(options: QueryWorkoutsOptions): Promise<QueryWorkoutsResult>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export type HealthDataType = 'steps' | 'distance' | 'calories' | 'totalCalories' | 'heartRate' | 'weight' | 'height';\n\nexport type HealthUnit = 'count' | 'meter' | 'kilocalorie' | 'bpm' | 'kilogram';\n\n/**\n * Data types that can be requested for read authorization.\n * Includes 'workouts' for querying workout sessions via queryWorkouts().\n */\nexport type ReadAuthorizationType = HealthDataType | 'workouts';\n\nexport interface AuthorizationOptions {\n /**\n * Data types that should be readable after authorization.\n * Include 'workouts' to enable queryWorkouts() method.\n */\n read?: ReadAuthorizationType[];\n /** Data types that should be writable after authorization. */\n write?: HealthDataType[];\n}\n\nexport interface AuthorizationStatus {\n /** Data types (and 'workouts') that are authorized for reading */\n readAuthorized: ReadAuthorizationType[];\n /** Data types (and 'workouts') that are denied for reading */\n readDenied: ReadAuthorizationType[];\n /** Data types that are authorized for writing */\n writeAuthorized: HealthDataType[];\n /** Data types that are denied for writing */\n writeDenied: HealthDataType[];\n}\n\nexport interface AvailabilityResult {\n available: boolean;\n /** Platform specific details (for debugging/diagnostics). */\n platform?: 'android' | 'web';\n reason?: string;\n}\n\nexport interface QueryOptions {\n /** The type of data to retrieve from the health store. */\n dataType: HealthDataType;\n /** Inclusive ISO 8601 start date (defaults to now - 1 day). */\n startDate?: string;\n /** Exclusive ISO 8601 end date (defaults to now). */\n endDate?: string;\n /** Maximum number of samples to return (defaults to 100). */\n limit?: number;\n /** Return results sorted ascending by start date (defaults to false). */\n ascending?: boolean;\n}\n\nexport interface HealthSample {\n dataType: HealthDataType;\n value: number;\n unit: HealthUnit;\n startDate: string;\n endDate: string;\n sourceName?: string;\n sourceId?: string;\n}\n\nexport interface ReadSamplesResult {\n samples: HealthSample[];\n}\n\nexport type WorkoutType =\n | 'running'\n | 'cycling'\n | 'walking'\n | 'swimming'\n | 'yoga'\n | 'strengthTraining'\n | 'hiking'\n | 'tennis'\n | 'basketball'\n | 'soccer'\n | 'americanFootball'\n | 'baseball'\n | 'crossTraining'\n | 'elliptical'\n | 'rowing'\n | 'stairClimbing'\n | 'traditionalStrengthTraining'\n | 'waterFitness'\n | 'waterPolo'\n | 'waterSports'\n | 'wrestling'\n | 'other';\n\nexport interface QueryWorkoutsOptions {\n /** Optional workout type filter. If omitted, all workout types are returned. */\n workoutType?: WorkoutType;\n /** Inclusive ISO 8601 start date (defaults to now - 1 day). */\n startDate?: string;\n /** Exclusive ISO 8601 end date (defaults to now). */\n endDate?: string;\n /** Maximum number of workouts to return (defaults to 100). */\n limit?: number;\n /** Return results sorted ascending by start date (defaults to false). */\n ascending?: boolean;\n}\n\nexport interface Workout {\n /** The type of workout. */\n workoutType: WorkoutType;\n /** Duration of the workout in seconds. */\n duration: number;\n /** Total energy burned in kilocalories (if available). */\n totalEnergyBurned?: number;\n /** Total distance in meters (if available). */\n totalDistance?: number;\n /** ISO 8601 start date of the workout. */\n startDate: string;\n /** ISO 8601 end date of the workout. */\n endDate: string;\n /** Source name that recorded the workout. */\n sourceName?: string;\n /** Source bundle identifier. */\n sourceId?: string;\n /** Additional metadata (if available). */\n metadata?: Record<string, string>;\n}\n\nexport interface QueryWorkoutsResult {\n workouts: Workout[];\n}\n\nexport interface WriteSampleOptions {\n dataType: HealthDataType;\n value: number;\n /**\n * Optional unit override. If omitted, the default unit for the data type is used\n * (count for `steps`, meter for `distance`, kilocalorie for `calories` and `totalCalories`, bpm for `heartRate`, kilogram for `weight`, meter for `height`).\n */\n unit?: HealthUnit;\n /** ISO 8601 start date for the sample. Defaults to now. */\n startDate?: string;\n /** ISO 8601 end date for the sample. Defaults to startDate. */\n endDate?: string;\n /** Metadata key-value pairs forwarded to the native APIs where supported. */\n metadata?: Record<string, string>;\n}\n\nexport interface HealthPlugin {\n /** Returns whether the current platform supports the native health SDK. */\n isAvailable(): Promise<AvailabilityResult>;\n /** Requests read/write access to the provided data types. */\n requestAuthorization(options: AuthorizationOptions): Promise<AuthorizationStatus>;\n /** Checks authorization status for the provided data types without prompting the user. */\n checkAuthorization(options: AuthorizationOptions): Promise<AuthorizationStatus>;\n /** Reads samples for the given data type within the specified time frame. */\n readSamples(options: QueryOptions): Promise<ReadSamplesResult>;\n /** Writes a single sample to the native health store. */\n saveSample(options: WriteSampleOptions): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ version: string }>} a Promise with version for this device\n * @throws An error if something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n\n /**\n * Opens the Health Connect settings screen.\n *\n * Use this to direct users to manage their Health Connect permissions\n * or to install Health Connect if not available.\n *\n * @throws An error if Health Connect settings cannot be opened\n */\n openHealthConnectSettings(): Promise<void>;\n\n /**\n * Shows the app's privacy policy for Health Connect.\n *\n * This displays the same privacy policy screen that Health Connect shows\n * when the user taps \"Privacy policy\" in the permissions dialog.\n *\n * The privacy policy URL can be configured by adding a string resource\n * named \"health_connect_privacy_policy_url\" in your app's strings.xml,\n * or by placing an HTML file at www/privacypolicy.html in your assets.\n *\n * @throws An error if the privacy policy cannot be displayed\n */\n showPrivacyPolicy(): Promise<void>;\n\n /**\n * Queries workout sessions from the native health store on Android (Health Connect).\n *\n * @param options Query options including optional workout type filter, date range, limit, and sort order\n * @returns A promise that resolves with the workout sessions\n * @throws An error if something went wrong\n */\n queryWorkouts(options: QueryWorkoutsOptions): Promise<QueryWorkoutsResult>;\n}\n"]}
|
package/package.json
CHANGED