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 a [resource file](https://developer.android.com/guide/topics/resources/providing-resources). You can reuse an existing one or create a new one. That allows you to fully utilise this SDK and to read the necessary data from apps that integrate with HealthConnect.
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
- <?xml version="1.0" encoding="utf-8"?>
84
- <resources>
85
- <array name="health_permissions">
86
- <item>androidx.health.permission.Nutrition.READ</item>
87
- <item>androidx.health.permission.ActiveCaloriesBurned.READ</item>
88
- <item>androidx.health.permission.TotalCaloriesBurned.READ</item>
89
- <item>androidx.health.permission.Steps.READ</item>
90
- <item>androidx.health.permission.Distance.READ</item>
91
- <item>androidx.health.permission.ElevationGained.READ</item>
92
- <item>androidx.health.permission.RestingHeartRate.READ</item>
93
- <item>androidx.health.permission.HeartRateVariabilityRmssd.READ</item>
94
- <item>androidx.health.permission.FloorsClimbed.READ</item>
95
- <item>androidx.health.permission.BasalMetabolicRate.READ</item>
96
- <item>androidx.health.permission.SleepSession.READ</item>
97
- <item>androidx.health.permission.HeartRate.READ</item>
98
- <item>androidx.health.permission.ExerciseSession.READ</item>
99
- <item>androidx.health.permission.Speed.READ</item>
100
- <item>androidx.health.permission.Power.READ</item>
101
- <item>androidx.health.permission.OxygenSaturation.READ</item>
102
- <item>androidx.health.permission.BloodGlucose.READ</item>
103
- <item>androidx.health.permission.RespiratoryRate.READ</item>
104
- <item>androidx.health.permission.Weight.READ</item>
105
- <item>androidx.health.permission.Height.READ</item>
106
- <item>androidx.health.permission.BodyFat.READ</item>
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. Now comes the `AndroidManifest.xml` modification part. Add the following query in the <manifest> node:
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. Then reference the permissions to your AndroidManifest.xml file in the activity that will call for health permissions. This meta-data reference should be added under the <activity> node, mostly in the <activity android:name=".MainActivity">.
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
- <meta-data
128
- android:name="health_permissions"
129
- android:resource="@array/health_permissions" />
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
- <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
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
 
@@ -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.2'
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
- val intent = connection.requestReadAuthorization().createIntent(
356
- reactApplicationContext, permissions
357
- )
373
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.TIRAMISU) {
374
+ val intent = connection.requestReadAuthorization().createIntent(
375
+ reactApplicationContext, permissions
376
+ )
358
377
 
359
- reactApplicationContext.currentActivity?.startActivityForResult(
360
- intent,
361
- REQUEST_CODE
362
- )
363
- promise.resolve(true)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-spike-sdk",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Spike API for health and productivity data from wearables and IoT devices",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -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.0"
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.9"
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