react-native-spike-sdk 2.2.0 → 2.2.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
CHANGED
|
@@ -75,45 +75,36 @@ Add Health Kit permissions descriptions to your `Info.plist` file.
|
|
|
75
75
|
|
|
76
76
|
## Android Setup <a name="android_setup"></a>
|
|
77
77
|
|
|
78
|
-
First of all you have to add the required health permissions to
|
|
79
|
-
|
|
80
|
-
1. Create config.xml in the following path: android/app/src/main/res/values. Content of this file must be the following:
|
|
78
|
+
First of all you have to add the required health permissions to your "AndroidManifest.xml" file
|
|
81
79
|
|
|
82
80
|
```xml
|
|
83
|
-
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
<item>androidx.health.permission.LeanBodyMass.READ</item>
|
|
108
|
-
<item>androidx.health.permission.BodyWaterMass.READ</item>
|
|
109
|
-
<item>androidx.health.permission.BodyTemperature.READ</item>
|
|
110
|
-
<item>androidx.health.permission.BloodPressure.READ</item>
|
|
111
|
-
<item>androidx.health.permission.BoneMass.READ</item>
|
|
112
|
-
</array>
|
|
113
|
-
</resources>
|
|
81
|
+
<uses-permission android:name="android.permission.health.READ_SLEEP "/>
|
|
82
|
+
<uses-permission android:name="android.permission.health.READ_WEIGHT" />
|
|
83
|
+
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED" />
|
|
84
|
+
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE" />
|
|
85
|
+
<uses-permission android:name="android.permission.health.READ_BLOOD_GLUCOSE" />
|
|
86
|
+
<uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE" />
|
|
87
|
+
<uses-permission android:name="android.permission.health.READ_BODY_FAT" />
|
|
88
|
+
<uses-permission android:name="android.permission.health.READ_BONE_MASS" />
|
|
89
|
+
<uses-permission android:name="android.permission.health.READ_EXERCISE" />
|
|
90
|
+
<uses-permission android:name="android.permission.health.READ_DISTANCE" />
|
|
91
|
+
<uses-permission android:name="android.permission.health.READ_ELEVATION_GAINED" />
|
|
92
|
+
<uses-permission android:name="android.permission.health.READ_FLOORS_CLIMBED" />
|
|
93
|
+
<uses-permission android:name="android.permission.health.READ_HEART_RATE" />
|
|
94
|
+
<uses-permission android:name="android.permission.health.READ_HEART_RATE_VARIABILITY" />
|
|
95
|
+
<uses-permission android:name="android.permission.health.READ_HEIGHT" />
|
|
96
|
+
<uses-permission android:name="android.permission.health.READ_OXYGEN_SATURATION" />
|
|
97
|
+
<uses-permission android:name="android.permission.health.READ_POWER" />
|
|
98
|
+
<uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE" />
|
|
99
|
+
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE" />
|
|
100
|
+
<uses-permission android:name="android.permission.health.READ_SPEED" />
|
|
101
|
+
<uses-permission android:name="android.permission.health.READ_STEPS" />
|
|
102
|
+
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED" />
|
|
103
|
+
<uses-permission android:name="android.permission.health.READ_BODY_TEMPERATURE" />
|
|
104
|
+
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE" />
|
|
114
105
|
```
|
|
115
106
|
|
|
116
|
-
2.
|
|
107
|
+
2. Also add the following query in the <manifest> node:
|
|
117
108
|
|
|
118
109
|
```xml
|
|
119
110
|
<queries>
|
|
@@ -121,21 +112,35 @@ First of all you have to add the required health permissions to a [resource file
|
|
|
121
112
|
</queries>
|
|
122
113
|
```
|
|
123
114
|
|
|
124
|
-
3.
|
|
115
|
+
3. As well as that you have to add intent filter to your activity definition so that you can request the permissions at runtime. This intent filter reference should be added under the <activity> node, mostly in the <activity android:name=".MainActivity">.
|
|
125
116
|
|
|
126
117
|
```xml
|
|
127
|
-
<
|
|
128
|
-
android:name="
|
|
129
|
-
|
|
118
|
+
<intent-filter>
|
|
119
|
+
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
|
|
120
|
+
</intent-filter>
|
|
130
121
|
```
|
|
131
|
-
|
|
132
|
-
4. As well as that you have to add intent filter to your activity definition so that you can request the permissions at runtime. This intent filter reference should be added under the <activity> node, mostly in the <activity android:name=".MainActivity">.
|
|
133
|
-
|
|
122
|
+
*For Android 14 support you also need to add additional intent-filters:
|
|
134
123
|
```xml
|
|
135
124
|
<intent-filter>
|
|
136
|
-
|
|
125
|
+
<action
|
|
126
|
+
android:name="android.intent.action.VIEW_PERMISSION_USAGE"/>
|
|
127
|
+
<category
|
|
128
|
+
android:name="android.intent.category.HEALTH_PERMISSIONS"/>
|
|
137
129
|
</intent-filter>
|
|
138
130
|
```
|
|
131
|
+
4. For Android 14 support additional manifest element inside application tag
|
|
132
|
+
```xml
|
|
133
|
+
<activity-alias
|
|
134
|
+
android:name="ViewPermissionUsageActivity"
|
|
135
|
+
android:exported="true"
|
|
136
|
+
android:targetActivity=".MainActivity"
|
|
137
|
+
android:permission="android.permission.START_VIEW_PERMISSION_USAGE">
|
|
138
|
+
<intent-filter>
|
|
139
|
+
<action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
|
|
140
|
+
<category android:name="android.intent.category.HEALTH_PERMISSIONS" />
|
|
141
|
+
</intent-filter>
|
|
142
|
+
</activity-alias>
|
|
143
|
+
```
|
|
139
144
|
|
|
140
145
|
5. In case permissions handling is not working, this might be related to launch mode being `singleTop`. This might be not needed, but some apps faced problems when requesting permissions. If you face them, then you should try removing the following line:
|
|
141
146
|
|
package/android/build.gradle
CHANGED
|
@@ -76,7 +76,7 @@ dependencies {
|
|
|
76
76
|
//noinspection GradleDynamicVersion
|
|
77
77
|
implementation "com.facebook.react:react-android:0.71.3"
|
|
78
78
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
79
|
-
implementation 'com.spikeapi.sdk:spike-sdk:3.0.
|
|
79
|
+
implementation 'com.spikeapi.sdk:spike-sdk:3.0.4'
|
|
80
80
|
implementation 'androidx.core:core-ktx:1.9.0'
|
|
81
81
|
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
|
|
82
82
|
implementation 'com.google.code.gson:gson:2.10.1'
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
package com.spikesdk
|
|
2
2
|
|
|
3
|
+
import android.os.Build
|
|
4
|
+
import android.os.Environment
|
|
5
|
+
import android.os.Environment.DIRECTORY_DOWNLOADS
|
|
6
|
+
import androidx.activity.ComponentActivity
|
|
7
|
+
import androidx.activity.result.ActivityResultCallback
|
|
8
|
+
import androidx.activity.result.ActivityResultLauncher
|
|
9
|
+
import androidx.activity.result.contract.ActivityResultContract
|
|
3
10
|
import com.facebook.react.bridge.Promise
|
|
4
11
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
12
|
import com.facebook.react.bridge.ReactContext
|
|
@@ -17,7 +24,18 @@ import kotlinx.coroutines.CoroutineScope
|
|
|
17
24
|
import kotlinx.coroutines.Dispatchers
|
|
18
25
|
import kotlinx.coroutines.SupervisorJob
|
|
19
26
|
import kotlinx.coroutines.launch
|
|
27
|
+
import java.io.File
|
|
28
|
+
import java.io.IOException
|
|
20
29
|
import java.time.OffsetDateTime
|
|
30
|
+
import java.util.UUID
|
|
31
|
+
|
|
32
|
+
fun <I, O> ComponentActivity.registerActivityResultLauncher(
|
|
33
|
+
contract: ActivityResultContract<I, O>,
|
|
34
|
+
callback: ActivityResultCallback<O>
|
|
35
|
+
): ActivityResultLauncher<I> {
|
|
36
|
+
val key = UUID.randomUUID().toString()
|
|
37
|
+
return activityResultRegistry.register(key, contract, callback)
|
|
38
|
+
}
|
|
21
39
|
|
|
22
40
|
class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
23
41
|
ReactContextBaseJavaModule(reactContext) {
|
|
@@ -348,19 +366,36 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
348
366
|
"Connection not found"
|
|
349
367
|
).mapException(), "Connection not found"
|
|
350
368
|
)
|
|
351
|
-
|
|
369
|
+
|
|
352
370
|
val permissions =
|
|
353
371
|
connection.getRequiredHealthPermissionsMetadata(dataType.toSpikeDataType())
|
|
354
372
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
373
|
+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.TIRAMISU) {
|
|
374
|
+
val intent = connection.requestReadAuthorization().createIntent(
|
|
375
|
+
reactApplicationContext, permissions
|
|
376
|
+
)
|
|
358
377
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
378
|
+
reactApplicationContext.currentActivity?.startActivityForResult(
|
|
379
|
+
intent,
|
|
380
|
+
REQUEST_CODE
|
|
381
|
+
)
|
|
382
|
+
promise.resolve(true)
|
|
383
|
+
} else {
|
|
384
|
+
val activity = reactApplicationContext.currentActivity
|
|
385
|
+
if (activity is ComponentActivity) {
|
|
386
|
+
val launcher =
|
|
387
|
+
activity.registerActivityResultLauncher(
|
|
388
|
+
connection.requestReadAuthorization()
|
|
389
|
+
) {
|
|
390
|
+
checkPermissionsGranted(connectionUUID, dataType, promise)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
launcher.launch(permissions)
|
|
394
|
+
promise.resolve(true)
|
|
395
|
+
} else {
|
|
396
|
+
promise.resolve(false)
|
|
397
|
+
}
|
|
398
|
+
}
|
|
364
399
|
}
|
|
365
400
|
|
|
366
401
|
private fun createLogger(connectionUUID: String): SpikeLogger {
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1
|
|
|
5
5
|
|
|
6
6
|
Pod::Spec.new do |s|
|
|
7
7
|
s.name = "react-native-spike-sdk"
|
|
8
|
-
s.version = "2.2.
|
|
8
|
+
s.version = "2.2.2"
|
|
9
9
|
s.summary = "Spike API for health and productivity data from wearables and IoT devices"
|
|
10
10
|
|
|
11
11
|
s.description = <<-DESC
|
|
@@ -25,7 +25,7 @@ Pod::Spec.new do |s|
|
|
|
25
25
|
s.swift_version = "5"
|
|
26
26
|
|
|
27
27
|
s.dependency "React-Core"
|
|
28
|
-
s.dependency "SpikeSDK", "~> 2.1.
|
|
28
|
+
s.dependency "SpikeSDK", "~> 2.1.10"
|
|
29
29
|
|
|
30
30
|
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
31
31
|
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|