@asiriindatissa/capacitor-health 9.0.0 → 9.0.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 +75 -54
- package/android/src/main/java/app/capgo/plugin/health/HealthManager.kt +15 -3
- package/android/src/main/java/app/capgo/plugin/health/HealthPlugin.kt +5 -4
- package/dist/docs.json +6 -6
- package/dist/esm/definitions.d.ts +5 -7
- package/dist/esm/definitions.js.map +1 -1
- package/package.json +4 -9
- package/README.md.backup +0 -625
- package/android/src/main/java/app/capgo/plugin/health/HealthManager.kt.backup +0 -657
- package/android/src/main/java/app/capgo/plugin/health/HealthPlugin.kt.backup +0 -512
package/README.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# @asiriindatissa/capacitor-health
|
|
2
2
|
|
|
3
|
-
Capacitor plugin to read
|
|
3
|
+
Capacitor plugin to read and write health metrics via Health Connect on Android. The TypeScript API provides a unified interface for health data access.
|
|
4
4
|
|
|
5
5
|
## Why Capacitor Health?
|
|
6
6
|
|
|
7
7
|
The only **free**, **unified** health data plugin for Capacitor supporting the latest native APIs:
|
|
8
8
|
|
|
9
|
-
- **Health Connect (Android)** - Uses Google's newest health platform
|
|
9
|
+
- **Health Connect (Android)** - Uses Google's newest health platform (replaces deprecated Google Fit)
|
|
10
10
|
- **Unified API** - TypeScript interface with consistent units
|
|
11
|
-
- **
|
|
11
|
+
- **Multiple metrics** - Steps, distance, calories, heart rate, weight, height
|
|
12
|
+
- **Read & Write** - Query historical data and save new health entries
|
|
12
13
|
- **Modern standards** - Supports Android 8.0+
|
|
13
14
|
|
|
14
|
-
Perfect for
|
|
15
|
+
Perfect for fitness apps, health trackers, wellness platforms, and medical applications.
|
|
15
16
|
|
|
16
17
|
## Install
|
|
17
18
|
|
|
@@ -25,11 +26,13 @@ npx cap sync
|
|
|
25
26
|
This plugin now uses [Health Connect](https://developer.android.com/health-and-fitness/guides/health-connect) instead of Google Fit. Make sure your app meets the requirements below:
|
|
26
27
|
|
|
27
28
|
1. **Min SDK 26+.** Health Connect is only available on Android 8.0 (API 26) and above. The plugin's Gradle setup already targets this level.
|
|
28
|
-
2. **Declare Health permissions.** The plugin manifest ships with the required `<uses-permission>` declarations (`
|
|
29
|
+
2. **Declare Health permissions.** The plugin manifest ships with the required `<uses-permission>` declarations (`READ_/WRITE_STEPS`, `READ_/WRITE_DISTANCE`, `READ_/WRITE_ACTIVE_CALORIES_BURNED`, `READ_/WRITE_HEART_RATE`, `READ_/WRITE_WEIGHT`, `READ_/WRITE_HEIGHT`, `READ_EXERCISE`). Your app does not need to duplicate them, but you must surface a user-facing rationale because the permissions are considered health sensitive.
|
|
29
30
|
3. **Ensure Health Connect is installed.** Devices on Android 14+ include it by default. For earlier versions the user must install _Health Connect by Android_ from the Play Store. The `Health.isAvailable()` helper exposes the current status so you can prompt accordingly.
|
|
30
31
|
4. **Request runtime access.** The plugin opens the Health Connect permission UI when you call `requestAuthorization`. You should still handle denial flows (e.g., show a message if `checkAuthorization` reports missing scopes).
|
|
31
32
|
5. **Provide a Privacy Policy.** Health Connect requires apps to display a privacy policy explaining how health data is used. See the [Privacy Policy Setup](#privacy-policy-setup) section below.
|
|
32
33
|
|
|
34
|
+
If you already used Google Fit in your project you can remove the associated dependencies (`play-services-fitness`, `play-services-auth`, OAuth configuration, etc.).
|
|
35
|
+
|
|
33
36
|
### Privacy Policy Setup
|
|
34
37
|
|
|
35
38
|
Health Connect requires your app to provide a privacy policy that explains how you handle health data. When users tap "Privacy policy" in the Health Connect permissions dialog, your app must display this information.
|
|
@@ -50,7 +53,7 @@ Place an HTML file at `android/app/src/main/assets/public/privacypolicy.html`:
|
|
|
50
53
|
<h1>Privacy Policy</h1>
|
|
51
54
|
<p>Your privacy policy content here...</p>
|
|
52
55
|
<h2>Health Data</h2>
|
|
53
|
-
<p>Explain how you collect, use, and protect
|
|
56
|
+
<p>Explain how you collect, use, and protect health data...</p>
|
|
54
57
|
</body>
|
|
55
58
|
</html>
|
|
56
59
|
```
|
|
@@ -91,26 +94,72 @@ if (!availability.available) {
|
|
|
91
94
|
console.warn('Health access unavailable:', availability.reason);
|
|
92
95
|
}
|
|
93
96
|
|
|
94
|
-
// Ask for read access
|
|
97
|
+
// Ask for separate read/write access scopes
|
|
98
|
+
// Include 'workouts' if you need to query workout sessions
|
|
95
99
|
await Health.requestAuthorization({
|
|
96
|
-
read: ['
|
|
100
|
+
read: ['steps', 'weight', 'workouts'],
|
|
101
|
+
write: ['weight'],
|
|
97
102
|
});
|
|
98
103
|
|
|
99
|
-
// Query
|
|
100
|
-
const {
|
|
101
|
-
|
|
104
|
+
// Query the last 50 step samples from the past 24 hours
|
|
105
|
+
const { samples } = await Health.readSamples({
|
|
106
|
+
dataType: 'steps',
|
|
107
|
+
startDate: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
|
|
102
108
|
endDate: new Date().toISOString(),
|
|
103
|
-
limit:
|
|
109
|
+
limit: 50,
|
|
104
110
|
});
|
|
105
111
|
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
// Persist a new body-weight entry (kilograms by default)
|
|
113
|
+
await Health.saveSample({
|
|
114
|
+
dataType: 'weight',
|
|
115
|
+
value: 74.3,
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Supported data types
|
|
120
|
+
|
|
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
|
+
| `weight` | `kilogram` | Body mass |
|
|
127
|
+
| `height` | `meter` | Body height |
|
|
128
|
+
|
|
129
|
+
All write operations expect the default unit shown above. On Android the `metadata` option is currently ignored by Health Connect.
|
|
130
|
+
|
|
131
|
+
### Workouts
|
|
132
|
+
|
|
133
|
+
To query workout sessions, you need to request read permission for `'workouts'`:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
// Request permission to read workouts
|
|
137
|
+
// IMPORTANT: To see totalEnergyBurned and totalDistance in workout data,
|
|
138
|
+
// you MUST also request permissions for 'calories' and 'distance'
|
|
139
|
+
await Health.requestAuthorization({
|
|
140
|
+
read: ['workouts', 'calories', 'distance'], // Include data types for workout metrics
|
|
141
|
+
write: [],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Query recent workouts
|
|
145
|
+
const { workouts } = await Health.queryWorkouts({
|
|
146
|
+
startDate: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(),
|
|
109
147
|
endDate: new Date().toISOString(),
|
|
110
|
-
limit:
|
|
148
|
+
limit: 10,
|
|
111
149
|
});
|
|
150
|
+
|
|
151
|
+
// Each workout may include:
|
|
152
|
+
// - workoutType, duration, startDate, endDate (always present)
|
|
153
|
+
// - totalEnergyBurned (if calories permission granted and data exists)
|
|
154
|
+
// - totalDistance (if distance permission granted and data exists)
|
|
112
155
|
```
|
|
113
156
|
|
|
157
|
+
**Note:**
|
|
158
|
+
|
|
159
|
+
- `'workouts'` is a special read-only permission type. You cannot write workouts with this plugin.
|
|
160
|
+
- 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` and `distance`, these fields will be missing from workout results.
|
|
161
|
+
- 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.
|
|
162
|
+
|
|
114
163
|
### Sleep
|
|
115
164
|
|
|
116
165
|
To query sleep sessions, you need to request read permission for `'sleep'`:
|
|
@@ -157,34 +206,6 @@ const { sleepSessions } = await Health.querySleep({
|
|
|
157
206
|
- `'sleep'` is a special read-only permission type. You cannot write sleep data with this plugin.
|
|
158
207
|
- Not all sleep sessions include detailed sleep stages. Some apps may only record the overall sleep duration.
|
|
159
208
|
|
|
160
|
-
### Hydration
|
|
161
|
-
|
|
162
|
-
To query hydration records, you need to request read permission for `'hydration'`:
|
|
163
|
-
|
|
164
|
-
```ts
|
|
165
|
-
// Request permission to read hydration data
|
|
166
|
-
await Health.requestAuthorization({
|
|
167
|
-
read: ['hydration'],
|
|
168
|
-
write: [],
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
// Query recent hydration records
|
|
172
|
-
const { hydrationRecords } = await Health.queryHydration({
|
|
173
|
-
startDate: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(),
|
|
174
|
-
endDate: new Date().toISOString(),
|
|
175
|
-
limit: 50,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
// Each hydration record includes:
|
|
179
|
-
// - volume (in liters), startDate, endDate (always present)
|
|
180
|
-
// - sourceName, sourceId (source app information)
|
|
181
|
-
// - metadata (optional, client record information)
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
**Note:**
|
|
185
|
-
|
|
186
|
-
- `'hydration'` is a special read-only permission type. You cannot write hydration data with this plugin.
|
|
187
|
-
|
|
188
209
|
## API
|
|
189
210
|
|
|
190
211
|
<docgen-index>
|
|
@@ -224,7 +245,7 @@ Returns whether the current platform supports the native health SDK.
|
|
|
224
245
|
requestAuthorization(options: AuthorizationOptions) => Promise<AuthorizationStatus>
|
|
225
246
|
```
|
|
226
247
|
|
|
227
|
-
Requests read access to the provided data types.
|
|
248
|
+
Requests read/write access to the provided data types.
|
|
228
249
|
|
|
229
250
|
| Param | Type |
|
|
230
251
|
| ------------- | --------------------------------------------------------------------- |
|
|
@@ -345,19 +366,19 @@ Queries hydration records from the native health store on Android (Health Connec
|
|
|
345
366
|
|
|
346
367
|
#### AuthorizationStatus
|
|
347
368
|
|
|
348
|
-
| Prop | Type | Description
|
|
349
|
-
| --------------------- | ------------------------------------ |
|
|
350
|
-
| **`readAuthorized`** | <code>ReadAuthorizationType[]</code> | Data types that are authorized for reading
|
|
351
|
-
| **`readDenied`** | <code>ReadAuthorizationType[]</code> | Data types that are denied for reading
|
|
352
|
-
| **`writeAuthorized`** | <code>
|
|
353
|
-
| **`writeDenied`** | <code>
|
|
369
|
+
| Prop | Type | Description |
|
|
370
|
+
| --------------------- | ------------------------------------ | --------------------------------------------------------- |
|
|
371
|
+
| **`readAuthorized`** | <code>ReadAuthorizationType[]</code> | Data types that are authorized for reading |
|
|
372
|
+
| **`readDenied`** | <code>ReadAuthorizationType[]</code> | Data types that are denied for reading |
|
|
373
|
+
| **`writeAuthorized`** | <code>[]</code> | Data types that are authorized for writing (always empty) |
|
|
374
|
+
| **`writeDenied`** | <code>[]</code> | Data types that are denied for writing (always empty) |
|
|
354
375
|
|
|
355
376
|
|
|
356
377
|
#### AuthorizationOptions
|
|
357
378
|
|
|
358
|
-
| Prop | Type | Description
|
|
359
|
-
| ---------- | ------------------------------------ |
|
|
360
|
-
| **`read`** | <code>ReadAuthorizationType[]</code> | Data types that should be readable after authorization.
|
|
379
|
+
| Prop | Type | Description |
|
|
380
|
+
| ---------- | ------------------------------------ | ------------------------------------------------------- |
|
|
381
|
+
| **`read`** | <code>ReadAuthorizationType[]</code> | Data types that should be readable after authorization. |
|
|
361
382
|
|
|
362
383
|
|
|
363
384
|
#### QuerySleepResult
|
|
@@ -6,14 +6,16 @@ import androidx.health.connect.client.records.HydrationRecord
|
|
|
6
6
|
import androidx.health.connect.client.records.SleepSessionRecord
|
|
7
7
|
import androidx.health.connect.client.request.ReadRecordsRequest
|
|
8
8
|
import androidx.health.connect.client.time.TimeRangeFilter
|
|
9
|
+
import androidx.health.connect.client.records.metadata.Metadata
|
|
10
|
+
import java.time.Duration
|
|
9
11
|
import com.getcapacitor.JSArray
|
|
10
12
|
import com.getcapacitor.JSObject
|
|
11
|
-
import java.time.Duration
|
|
12
13
|
import java.time.Instant
|
|
13
14
|
import java.time.ZoneId
|
|
14
15
|
import java.time.ZoneOffset
|
|
15
16
|
import java.time.format.DateTimeFormatter
|
|
16
17
|
import kotlin.math.min
|
|
18
|
+
import kotlin.collections.buildSet
|
|
17
19
|
|
|
18
20
|
class HealthManager {
|
|
19
21
|
|
|
@@ -60,14 +62,18 @@ class HealthManager {
|
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
val writeAuthorized = JSArray()
|
|
66
|
+
val writeDenied = JSArray()
|
|
67
|
+
|
|
63
68
|
return JSObject().apply {
|
|
64
69
|
put("readAuthorized", readAuthorized)
|
|
65
70
|
put("readDenied", readDenied)
|
|
66
|
-
put("writeAuthorized",
|
|
67
|
-
put("writeDenied",
|
|
71
|
+
put("writeAuthorized", writeAuthorized)
|
|
72
|
+
put("writeDenied", writeDenied)
|
|
68
73
|
}
|
|
69
74
|
}
|
|
70
75
|
|
|
76
|
+
|
|
71
77
|
fun parseInstant(value: String?, defaultInstant: Instant): Instant {
|
|
72
78
|
if (value.isNullOrBlank()) {
|
|
73
79
|
return defaultInstant
|
|
@@ -75,6 +81,12 @@ class HealthManager {
|
|
|
75
81
|
return Instant.parse(value)
|
|
76
82
|
}
|
|
77
83
|
|
|
84
|
+
|
|
85
|
+
private fun zoneOffset(instant: Instant): ZoneOffset? {
|
|
86
|
+
return ZoneId.systemDefault().rules.getOffset(instant)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
78
90
|
suspend fun querySleep(
|
|
79
91
|
client: HealthConnectClient,
|
|
80
92
|
startTime: Instant,
|
|
@@ -4,9 +4,11 @@ import android.app.Activity
|
|
|
4
4
|
import android.content.Intent
|
|
5
5
|
import android.net.Uri
|
|
6
6
|
import androidx.activity.result.ActivityResult
|
|
7
|
+
import com.getcapacitor.JSArray
|
|
7
8
|
import com.getcapacitor.JSObject
|
|
8
9
|
import com.getcapacitor.Plugin
|
|
9
10
|
import com.getcapacitor.PluginCall
|
|
11
|
+
import com.getcapacitor.PluginMethod
|
|
10
12
|
import com.getcapacitor.annotation.ActivityCallback
|
|
11
13
|
import com.getcapacitor.annotation.CapacitorPlugin
|
|
12
14
|
import androidx.health.connect.client.HealthConnectClient
|
|
@@ -27,7 +29,7 @@ data class ReadAuthorizationTypes(
|
|
|
27
29
|
|
|
28
30
|
@CapacitorPlugin(name = "Health")
|
|
29
31
|
class HealthPlugin : Plugin() {
|
|
30
|
-
private val pluginVersion = "
|
|
32
|
+
private val pluginVersion = "7.2.14"
|
|
31
33
|
private val manager = HealthManager()
|
|
32
34
|
private val pluginScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
|
33
35
|
private val permissionContract = PermissionController.createRequestPermissionResultContract()
|
|
@@ -94,8 +96,6 @@ class HealthPlugin : Plugin() {
|
|
|
94
96
|
try {
|
|
95
97
|
startActivityForResult(call, intent, "handlePermissionResult")
|
|
96
98
|
} catch (e: Exception) {
|
|
97
|
-
pendingIncludeSleep = false
|
|
98
|
-
pendingIncludeHydration = false
|
|
99
99
|
call.reject("Failed to launch Health Connect permission request.", null, e)
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -139,8 +139,9 @@ class HealthPlugin : Plugin() {
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
|
|
142
143
|
private fun parseReadAuthorizationTypes(call: PluginCall, key: String): ReadAuthorizationTypes {
|
|
143
|
-
val array = call.getArray(key) ?:
|
|
144
|
+
val array = call.getArray(key) ?: JSArray()
|
|
144
145
|
var includeSleep = false
|
|
145
146
|
var includeHydration = false
|
|
146
147
|
for (i in 0 until array.length()) {
|
package/dist/docs.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"returns": "Promise<AuthorizationStatus>",
|
|
31
31
|
"tags": [],
|
|
32
|
-
"docs": "Requests read access to the provided data types.",
|
|
32
|
+
"docs": "Requests read/write access to the provided data types.",
|
|
33
33
|
"complexTypes": [
|
|
34
34
|
"AuthorizationStatus",
|
|
35
35
|
"AuthorizationOptions"
|
|
@@ -230,16 +230,16 @@
|
|
|
230
230
|
{
|
|
231
231
|
"name": "writeAuthorized",
|
|
232
232
|
"tags": [],
|
|
233
|
-
"docs": "Data types that are authorized for writing",
|
|
233
|
+
"docs": "Data types that are authorized for writing (always empty)",
|
|
234
234
|
"complexTypes": [],
|
|
235
|
-
"type": "
|
|
235
|
+
"type": "[]"
|
|
236
236
|
},
|
|
237
237
|
{
|
|
238
238
|
"name": "writeDenied",
|
|
239
239
|
"tags": [],
|
|
240
|
-
"docs": "Data types that are denied for writing",
|
|
240
|
+
"docs": "Data types that are denied for writing (always empty)",
|
|
241
241
|
"complexTypes": [],
|
|
242
|
-
"type": "
|
|
242
|
+
"type": "[]"
|
|
243
243
|
}
|
|
244
244
|
]
|
|
245
245
|
},
|
|
@@ -253,7 +253,7 @@
|
|
|
253
253
|
{
|
|
254
254
|
"name": "read",
|
|
255
255
|
"tags": [],
|
|
256
|
-
"docs": "Data types that should be readable after authorization
|
|
256
|
+
"docs": "Data types that should be readable after authorization.",
|
|
257
257
|
"complexTypes": [
|
|
258
258
|
"ReadAuthorizationType"
|
|
259
259
|
],
|
|
@@ -7,8 +7,6 @@ export type ReadAuthorizationType = 'sleep' | 'hydration';
|
|
|
7
7
|
export interface AuthorizationOptions {
|
|
8
8
|
/**
|
|
9
9
|
* Data types that should be readable after authorization.
|
|
10
|
-
* Include 'sleep' to enable querySleep() method.
|
|
11
|
-
* Include 'hydration' to enable queryHydration() method.
|
|
12
10
|
*/
|
|
13
11
|
read?: ReadAuthorizationType[];
|
|
14
12
|
}
|
|
@@ -17,10 +15,10 @@ export interface AuthorizationStatus {
|
|
|
17
15
|
readAuthorized: ReadAuthorizationType[];
|
|
18
16
|
/** Data types that are denied for reading */
|
|
19
17
|
readDenied: ReadAuthorizationType[];
|
|
20
|
-
/** Data types that are authorized for writing */
|
|
21
|
-
writeAuthorized:
|
|
22
|
-
/** Data types that are denied for writing */
|
|
23
|
-
writeDenied:
|
|
18
|
+
/** Data types that are authorized for writing (always empty) */
|
|
19
|
+
writeAuthorized: [];
|
|
20
|
+
/** Data types that are denied for writing (always empty) */
|
|
21
|
+
writeDenied: [];
|
|
24
22
|
}
|
|
25
23
|
export interface AvailabilityResult {
|
|
26
24
|
available: boolean;
|
|
@@ -98,7 +96,7 @@ export interface QueryHydrationResult {
|
|
|
98
96
|
export interface HealthPlugin {
|
|
99
97
|
/** Returns whether the current platform supports the native health SDK. */
|
|
100
98
|
isAvailable(): Promise<AvailabilityResult>;
|
|
101
|
-
/** Requests read access to the provided data types. */
|
|
99
|
+
/** Requests read/write access to the provided data types. */
|
|
102
100
|
requestAuthorization(options: AuthorizationOptions): Promise<AuthorizationStatus>;
|
|
103
101
|
/** Checks authorization status for the provided data types without prompting the user. */
|
|
104
102
|
checkAuthorization(options: AuthorizationOptions): Promise<AuthorizationStatus>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Data types that can be requested for read authorization.\n * Includes 'sleep' for querying sleep sessions via querySleep().\n * Includes 'hydration' for querying hydration records via queryHydration().\n */\nexport type ReadAuthorizationType = 'sleep' | 'hydration';\n\nexport interface AuthorizationOptions {\n /**\n * Data types that should be readable after authorization.\n
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Data types that can be requested for read authorization.\n * Includes 'sleep' for querying sleep sessions via querySleep().\n * Includes 'hydration' for querying hydration records via queryHydration().\n */\nexport type ReadAuthorizationType = 'sleep' | 'hydration';\n\nexport interface AuthorizationOptions {\n /**\n * Data types that should be readable after authorization.\n */\n read?: ReadAuthorizationType[];\n}\n\nexport interface AuthorizationStatus {\n /** Data types that are authorized for reading */\n readAuthorized: ReadAuthorizationType[];\n /** Data types that are denied for reading */\n readDenied: ReadAuthorizationType[];\n /** Data types that are authorized for writing (always empty) */\n writeAuthorized: [];\n /** Data types that are denied for writing (always empty) */\n writeDenied: [];\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 type SleepStage = 'unknown' | 'awake' | 'sleeping' | 'outOfBed' | 'awakeInBed' | 'light' | 'deep' | 'rem';\n\nexport interface QuerySleepOptions {\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 sleep sessions 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 SleepStageRecord {\n /** The sleep stage type. */\n stage: SleepStage;\n /** ISO 8601 start date of this sleep stage. */\n startDate: string;\n /** ISO 8601 end date of this sleep stage. */\n endDate: string;\n}\n\nexport interface SleepSession {\n /** Title/name of the sleep session (if available). */\n title?: string;\n /** Duration of the sleep session in seconds. */\n duration: number;\n /** ISO 8601 start date of the sleep session. */\n startDate: string;\n /** ISO 8601 end date of the sleep session. */\n endDate: string;\n /** Array of sleep stages during the session (if available). */\n stages?: SleepStageRecord[];\n /** Source name that recorded the sleep session. */\n sourceName?: string;\n /** Source bundle identifier. */\n sourceId?: string;\n /** Additional metadata (if available). */\n metadata?: Record<string, string>;\n}\n\nexport interface QuerySleepResult {\n sleepSessions: SleepSession[];\n}\n\nexport interface QueryHydrationOptions {\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 hydration records 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 HydrationRecord {\n /** Volume of water consumed in liters. */\n volume: number;\n /** ISO 8601 start date of the hydration record. */\n startDate: string;\n /** ISO 8601 end date of the hydration record. */\n endDate: string;\n /** Source name that recorded the hydration. */\n sourceName?: string;\n /** Source bundle identifier. */\n sourceId?: string;\n /** Additional metadata (if available). */\n metadata?: Record<string, string>;\n}\n\nexport interface QueryHydrationResult {\n hydrationRecords: HydrationRecord[];\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\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 sleep sessions from the native health store on Android (Health Connect).\n *\n * @param options Query options including date range, limit, and sort order\n * @returns A promise that resolves with the sleep sessions\n * @throws An error if something went wrong\n */\n querySleep(options: QuerySleepOptions): Promise<QuerySleepResult>;\n\n /**\n * Queries hydration records from the native health store on Android (Health Connect).\n *\n * @param options Query options including date range, limit, and sort order\n * @returns A promise that resolves with the hydration records\n * @throws An error if something went wrong\n */\n queryHydration(options: QueryHydrationOptions): Promise<QueryHydrationResult>;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asiriindatissa/capacitor-health",
|
|
3
|
-
"version": "9.0.
|
|
4
|
-
"description": "Capacitor plugin to
|
|
3
|
+
"version": "9.0.2",
|
|
4
|
+
"description": "Capacitor plugin to interact with data from Health Connect on Android",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/esm/index.d.ts",
|
|
@@ -28,9 +28,7 @@
|
|
|
28
28
|
"android",
|
|
29
29
|
"health-connect",
|
|
30
30
|
"health",
|
|
31
|
-
"
|
|
32
|
-
"hydration",
|
|
33
|
-
"wellness"
|
|
31
|
+
"fitness"
|
|
34
32
|
],
|
|
35
33
|
"scripts": {
|
|
36
34
|
"verify": "npm run verify:android && npm run verify:web",
|
|
@@ -53,9 +51,6 @@
|
|
|
53
51
|
"@ionic/eslint-config": "^0.4.0",
|
|
54
52
|
"@ionic/prettier-config": "^4.0.0",
|
|
55
53
|
"@types/node": "^24.10.1",
|
|
56
|
-
"@ionic/eslint-config": "^0.4.0",
|
|
57
|
-
"@ionic/prettier-config": "^4.0.0",
|
|
58
|
-
"@types/node": "^24.10.1",
|
|
59
54
|
"eslint": "^8.57.1",
|
|
60
55
|
"eslint-plugin-import": "^2.31.0",
|
|
61
56
|
"prettier": "^3.6.2",
|
|
@@ -77,4 +72,4 @@
|
|
|
77
72
|
"src": "android"
|
|
78
73
|
}
|
|
79
74
|
}
|
|
80
|
-
}
|
|
75
|
+
}
|