@flomentumsolutions/capacitor-health-extended 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapacitorHealthExtended'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '13.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 - Martin Ley1
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/Package.swift ADDED
@@ -0,0 +1,28 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapacitorHealth",
6
+ platforms: [.iOS(.v13)],
7
+ products: [
8
+ .library(
9
+ name: "CapacitorHealth",
10
+ targets: ["HealthPluginPlugin"])
11
+ ],
12
+ dependencies: [
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
14
+ ],
15
+ targets: [
16
+ .target(
17
+ name: "HealthPluginPlugin",
18
+ dependencies: [
19
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
+ .product(name: "Cordova", package: "capacitor-swift-pm")
21
+ ],
22
+ path: "ios/Sources/HealthPluginPlugin"),
23
+ .testTarget(
24
+ name: "HealthPluginPluginTests",
25
+ dependencies: ["HealthPluginPlugin"],
26
+ path: "ios/Tests/HealthPluginPluginTests")
27
+ ]
28
+ )
package/README.md ADDED
@@ -0,0 +1,343 @@
1
+ # capacitor-health
2
+
3
+ Capacitor plugin to query data from Apple Health and Google Health Connect
4
+
5
+ ## Thanks and attribution
6
+
7
+ Some parts, concepts and ideas are borrowed from [cordova-plugin-health](https://github.com/dariosalvi78/cordova-plugin-health/). Big thanks to [@dariosalvi78](https://github.com/dariosalvi78) for the support.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install capacitor-health-extended
13
+ npx cap sync
14
+ ```
15
+
16
+ ## Setup
17
+
18
+ ### iOS
19
+
20
+ * Make sure your app id has the 'HealthKit' entitlement when this plugin is installed (see iOS dev center).
21
+ * Also, make sure your app and App Store description comply with the Apple review guidelines.
22
+ * There are two keys to be added to the info.plist file: NSHealthShareUsageDescription and NSHealthUpdateUsageDescription.
23
+
24
+ ### Android
25
+
26
+ * Android Manifest in root tag right after opening manifest tag
27
+ ```xml
28
+ <!-- Make Health Connect visible to detect installation -->
29
+ <queries>
30
+ <package android:name="com.google.android.apps.healthdata" />
31
+ </queries>
32
+
33
+ <!-- Declare permissions you’ll request -->
34
+ <uses-permission android:name="android.permission.INTERNET" />
35
+ <uses-permission android:name="android.permission.health.READ_STEPS"/>
36
+ <uses-permission android:name="android.permission.health.READ_EXERCISE"/>
37
+ <uses-permission android:name="android.permission.health.READ_WEIGHT" />
38
+ <uses-permission android:name="android.permission.health.READ_DISTANCE"/>
39
+ <uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED"/>
40
+ <uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED"/>
41
+ <uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
42
+ ```
43
+
44
+
45
+ * Android Manifest in application tag
46
+ ```xml
47
+ <!-- Handle Health Connect rationale (Android 13-) -->
48
+ <activity
49
+ android:name=".PermissionsRationaleActivity"
50
+ android:exported="true">
51
+ <intent-filter>
52
+ <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE"/>
53
+ <category android:name="android.intent.category.HEALTH_PERMISSIONS"/>
54
+ </intent-filter>
55
+ </activity>
56
+
57
+ <!-- Handle Android 14+ alias -->
58
+ <activity-alias
59
+ android:name="ViewPermissionUsageActivity"
60
+ android:exported="true"
61
+ android:targetActivity=".PermissionsRationaleActivity"
62
+ android:permission="android.permission.START_VIEW_PERMISSION_USAGE">
63
+ <intent-filter>
64
+ <action android:name="android.intent.action.VIEW_PERMISSION_USAGE"/>
65
+ <category android:name="android.intent.category.HEALTH_PERMISSIONS"/>
66
+ </intent-filter>
67
+ </activity-alias>
68
+ ```
69
+
70
+ * Android Manifest in application tag for secure WebView content
71
+ ```xml
72
+ <!-- Configure secure WebView and allow HTTPS loading -->
73
+ <application
74
+ android:usesCleartextTraffic="false"
75
+ android:networkSecurityConfig="@xml/network_security_config">
76
+ ...
77
+ </application>
78
+ ```
79
+
80
+ * Create `res/xml/network_security_config.xml` with:
81
+
82
+ ```xml
83
+ <?xml version="1.0" encoding="utf-8"?>
84
+ <network-security-config>
85
+ <base-config cleartextTrafficPermitted="false">
86
+ <trust-anchors>
87
+ <certificates src="system"/>
88
+ </trust-anchors>
89
+ </base-config>
90
+ </network-security-config>
91
+ ```
92
+
93
+ This setup ensures your WebView will load HTTPS content securely and complies with Android's default network security policy.
94
+ ```
95
+
96
+ ## API
97
+
98
+ <docgen-index>
99
+
100
+ * [`isHealthAvailable()`](#ishealthavailable)
101
+ * [`checkHealthPermissions(...)`](#checkhealthpermissions)
102
+ * [`requestHealthPermissions(...)`](#requesthealthpermissions)
103
+ * [`openAppleHealthSettings()`](#openapplehealthsettings)
104
+ * [`openHealthConnectSettings()`](#openhealthconnectsettings)
105
+ * [`showHealthConnectInPlayStore()`](#showhealthconnectinplaystore)
106
+ * [`queryAggregated(...)`](#queryaggregated)
107
+ * [`queryWorkouts(...)`](#queryworkouts)
108
+ * [Interfaces](#interfaces)
109
+ * [Type Aliases](#type-aliases)
110
+
111
+ </docgen-index>
112
+
113
+ <docgen-api>
114
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
115
+
116
+ ### isHealthAvailable()
117
+
118
+ ```typescript
119
+ isHealthAvailable() => Promise<{ available: boolean; }>
120
+ ```
121
+
122
+ Checks if health API is available.
123
+ Android: If false is returned, the Google Health Connect app is probably not installed.
124
+ See showHealthConnectInPlayStore()
125
+
126
+ **Returns:** <code>Promise&lt;{ available: boolean; }&gt;</code>
127
+
128
+ --------------------
129
+
130
+
131
+ ### checkHealthPermissions(...)
132
+
133
+ ```typescript
134
+ checkHealthPermissions(permissions: PermissionsRequest) => Promise<PermissionResponse>
135
+ ```
136
+
137
+ Android only: Returns for each given permission, if it was granted by the underlying health API
138
+
139
+ | Param | Type | Description |
140
+ | ----------------- | ----------------------------------------------------------------- | -------------------- |
141
+ | **`permissions`** | <code><a href="#permissionsrequest">PermissionsRequest</a></code> | permissions to query |
142
+
143
+ **Returns:** <code>Promise&lt;<a href="#permissionresponse">PermissionResponse</a>&gt;</code>
144
+
145
+ --------------------
146
+
147
+
148
+ ### requestHealthPermissions(...)
149
+
150
+ ```typescript
151
+ requestHealthPermissions(permissions: PermissionsRequest) => Promise<PermissionResponse>
152
+ ```
153
+
154
+ Requests the permissions from the user.
155
+
156
+ Android: Apps can ask only a few times for permissions, after that the user has to grant them manually in
157
+ the Health Connect app. See openHealthConnectSettings()
158
+
159
+ iOS: If the permissions are already granted or denied, this method will just return without asking the user. In iOS
160
+ we can't really detect if a user granted or denied a permission. The return value reflects the assumption that all
161
+ permissions were granted.
162
+
163
+ | Param | Type | Description |
164
+ | ----------------- | ----------------------------------------------------------------- | ---------------------- |
165
+ | **`permissions`** | <code><a href="#permissionsrequest">PermissionsRequest</a></code> | permissions to request |
166
+
167
+ **Returns:** <code>Promise&lt;<a href="#permissionresponse">PermissionResponse</a>&gt;</code>
168
+
169
+ --------------------
170
+
171
+
172
+ ### openAppleHealthSettings()
173
+
174
+ ```typescript
175
+ openAppleHealthSettings() => Promise<void>
176
+ ```
177
+
178
+ Opens the apps settings, which is kind of wrong, because health permissions are configured under:
179
+ Settings &gt; Apps &gt; (Apple) Health &gt; Access and Devices &gt; [app-name]
180
+ But we can't go there directly.
181
+
182
+ --------------------
183
+
184
+
185
+ ### openHealthConnectSettings()
186
+
187
+ ```typescript
188
+ openHealthConnectSettings() => Promise<void>
189
+ ```
190
+
191
+ Opens the Google Health Connect app
192
+
193
+ --------------------
194
+
195
+
196
+ ### showHealthConnectInPlayStore()
197
+
198
+ ```typescript
199
+ showHealthConnectInPlayStore() => Promise<void>
200
+ ```
201
+
202
+ Opens the Google Health Connect app in PlayStore
203
+
204
+ --------------------
205
+
206
+
207
+ ### queryAggregated(...)
208
+
209
+ ```typescript
210
+ queryAggregated(request: QueryAggregatedRequest) => Promise<QueryAggregatedResponse>
211
+ ```
212
+
213
+ Query aggregated data
214
+
215
+ | Param | Type |
216
+ | ------------- | ------------------------------------------------------------------------- |
217
+ | **`request`** | <code><a href="#queryaggregatedrequest">QueryAggregatedRequest</a></code> |
218
+
219
+ **Returns:** <code>Promise&lt;<a href="#queryaggregatedresponse">QueryAggregatedResponse</a>&gt;</code>
220
+
221
+ --------------------
222
+
223
+
224
+ ### queryWorkouts(...)
225
+
226
+ ```typescript
227
+ queryWorkouts(request: QueryWorkoutRequest) => Promise<QueryWorkoutResponse>
228
+ ```
229
+
230
+ Query workouts
231
+
232
+ | Param | Type |
233
+ | ------------- | ------------------------------------------------------------------- |
234
+ | **`request`** | <code><a href="#queryworkoutrequest">QueryWorkoutRequest</a></code> |
235
+
236
+ **Returns:** <code>Promise&lt;<a href="#queryworkoutresponse">QueryWorkoutResponse</a>&gt;</code>
237
+
238
+ --------------------
239
+
240
+
241
+ ### Interfaces
242
+
243
+
244
+ #### PermissionResponse
245
+
246
+ | Prop | Type |
247
+ | ----------------- | ------------------------------------------ |
248
+ | **`permissions`** | <code>{ [key: string]: boolean; }[]</code> |
249
+
250
+
251
+ #### PermissionsRequest
252
+
253
+ | Prop | Type |
254
+ | ----------------- | ------------------------------- |
255
+ | **`permissions`** | <code>HealthPermission[]</code> |
256
+
257
+
258
+ #### QueryAggregatedResponse
259
+
260
+ | Prop | Type |
261
+ | -------------------- | ------------------------------- |
262
+ | **`aggregatedData`** | <code>AggregatedSample[]</code> |
263
+
264
+
265
+ #### AggregatedSample
266
+
267
+ | Prop | Type |
268
+ | --------------- | ------------------- |
269
+ | **`startDate`** | <code>string</code> |
270
+ | **`endDate`** | <code>string</code> |
271
+ | **`value`** | <code>number</code> |
272
+
273
+
274
+ #### QueryAggregatedRequest
275
+
276
+ | Prop | Type |
277
+ | --------------- | ---------------------------------- |
278
+ | **`startDate`** | <code>string</code> |
279
+ | **`endDate`** | <code>string</code> |
280
+ | **`dataType`** | <code>'steps' \| 'calories'</code> |
281
+ | **`bucket`** | <code>string</code> |
282
+
283
+
284
+ #### QueryWorkoutResponse
285
+
286
+ | Prop | Type |
287
+ | -------------- | ---------------------- |
288
+ | **`workouts`** | <code>Workout[]</code> |
289
+
290
+
291
+ #### Workout
292
+
293
+ | Prop | Type |
294
+ | -------------------- | ------------------------------ |
295
+ | **`startDate`** | <code>string</code> |
296
+ | **`endDate`** | <code>string</code> |
297
+ | **`workoutType`** | <code>string</code> |
298
+ | **`sourceName`** | <code>string</code> |
299
+ | **`id`** | <code>string</code> |
300
+ | **`duration`** | <code>number</code> |
301
+ | **`distance`** | <code>number</code> |
302
+ | **`calories`** | <code>number</code> |
303
+ | **`sourceBundleId`** | <code>string</code> |
304
+ | **`route`** | <code>RouteSample[]</code> |
305
+ | **`heartRate`** | <code>HeartRateSample[]</code> |
306
+
307
+
308
+ #### RouteSample
309
+
310
+ | Prop | Type |
311
+ | --------------- | ------------------- |
312
+ | **`timestamp`** | <code>string</code> |
313
+ | **`lat`** | <code>number</code> |
314
+ | **`lng`** | <code>number</code> |
315
+ | **`alt`** | <code>number</code> |
316
+
317
+
318
+ #### HeartRateSample
319
+
320
+ | Prop | Type |
321
+ | --------------- | ------------------- |
322
+ | **`timestamp`** | <code>string</code> |
323
+ | **`bpm`** | <code>number</code> |
324
+
325
+
326
+ #### QueryWorkoutRequest
327
+
328
+ | Prop | Type |
329
+ | ---------------------- | -------------------- |
330
+ | **`startDate`** | <code>string</code> |
331
+ | **`endDate`** | <code>string</code> |
332
+ | **`includeHeartRate`** | <code>boolean</code> |
333
+ | **`includeRoute`** | <code>boolean</code> |
334
+
335
+
336
+ ### Type Aliases
337
+
338
+
339
+ #### HealthPermission
340
+
341
+ <code>'READ_STEPS' | 'READ_WORKOUTS' | 'READ_CALORIES' | 'READ_DISTANCE' | 'READ_HEART_RATE' | 'READ_ROUTE'</code>
342
+
343
+ </docgen-api>
@@ -0,0 +1,70 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
+ }
7
+
8
+ buildscript {
9
+ ext {
10
+ kotlin_version = '2.0.20'
11
+ }
12
+ repositories {
13
+ google()
14
+ mavenCentral()
15
+ }
16
+ dependencies {
17
+ classpath 'com.android.tools.build:gradle:8.10.1'
18
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
19
+ }
20
+ }
21
+
22
+ apply plugin: 'com.android.library'
23
+ apply plugin: 'org.jetbrains.kotlin.android'
24
+
25
+ android {
26
+ namespace "com.flomentum.health.capacitor"
27
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
28
+ defaultConfig {
29
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 26
30
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
31
+ versionCode 1
32
+ versionName "1.0"
33
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
34
+ }
35
+ buildTypes {
36
+ release {
37
+ minifyEnabled false
38
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
39
+ }
40
+ }
41
+ lintOptions {
42
+ abortOnError false
43
+ }
44
+ compileOptions {
45
+ sourceCompatibility JavaVersion.VERSION_17
46
+ targetCompatibility JavaVersion.VERSION_17
47
+ }
48
+ kotlinOptions {
49
+ jvmTarget = '17'
50
+ }
51
+ }
52
+
53
+ repositories {
54
+ google()
55
+ mavenCentral()
56
+ }
57
+
58
+
59
+ dependencies {
60
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
61
+ implementation project(':capacitor-android')
62
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
63
+
64
+ implementation 'androidx.health.connect:connect-client:1.1.0-rc02'
65
+ implementation 'androidx.core:core-ktx:1.13.1'
66
+
67
+ testImplementation "junit:junit:$junitVersion"
68
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
69
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
70
+ }
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.flomentum.health.capacitor">
2
+
3
+ </manifest>