spotny-sdk 1.0.33 → 1.0.35

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.
@@ -111,7 +111,22 @@ class SpotnySdkModule(private val reactContext: ReactApplicationContext) :
111
111
 
112
112
  private fun setupBeaconManager() {
113
113
  BeaconManager.setDebug(false)
114
- beaconManager.beaconParsers.add(BeaconParser().setBeaconLayout(IBEACON_LAYOUT))
114
+ beaconManager.setEnableScheduledScanJobs(false)
115
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
116
+ val channelId = "spotny_sdk_channel"
117
+ val notifManager = reactContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
118
+ val channel = NotificationChannel(channelId, "Spotny SDK", NotificationManager.IMPORTANCE_LOW)
119
+ notifManager.createNotificationChannel(channel)
120
+ }
121
+ val notification = NotificationCompat.Builder(reactContext, "spotny_sdk_channel")
122
+ .setSmallIcon(reactContext.applicationInfo.icon.takeIf { it != 0 } ?: android.R.drawable.ic_dialog_info)
123
+ .setContentTitle("Spotny")
124
+ .setContentText("Scanning for nearby beacons…")
125
+ .build()
126
+ beaconManager.enableForegroundServiceScanning(notification, 8765)
127
+ if (beaconManager.beaconParsers.isEmpty()) {
128
+ beaconManager.beaconParsers.add(BeaconParser().setBeaconLayout(IBEACON_LAYOUT))
129
+ }
115
130
  beaconManager.foregroundScanPeriod = 1_100L
116
131
  beaconManager.foregroundBetweenScanPeriod = 0L
117
132
  beaconManager.backgroundScanPeriod = 10_000L
@@ -152,8 +167,9 @@ class SpotnySdkModule(private val reactContext: ReactApplicationContext) :
152
167
  try {
153
168
  beaconManager.removeAllMonitorNotifiers()
154
169
  beaconManager.removeAllRangeNotifiers()
155
- beaconManager.stopRangingBeaconsInRegion(Region("SpotnySDK_General", null, null, null))
156
- beaconManager.stopMonitoringBeaconsInRegion(Region("SpotnySDK_General", null, null, null))
170
+ val region = Region("SpotnySDK_General", Identifier.parse(BEACON_UUID), null, null)
171
+ beaconManager.stopRangingBeaconsInRegion(region)
172
+ beaconManager.stopMonitoringBeaconsInRegion(region)
157
173
  } catch (_: RemoteException) {}
158
174
 
159
175
  cleanupAllState()
@@ -169,12 +185,13 @@ class SpotnySdkModule(private val reactContext: ReactApplicationContext) :
169
185
  override fun isScanning(promise: Promise) = promise.resolve(scanning)
170
186
 
171
187
  override fun initialize(config: ReadableMap?, promise: Promise) {
172
- config?.getDouble("maxDetectionDistance").takeIf { config?.hasKey("maxDetectionDistance") == true }
173
- ?.let { maxDetectionDistance = it; Log.d(TAG, "maxDetectionDistance = $it m") }
188
+ if (config?.hasKey("maxDetectionDistance") == true)
189
+ config.getDouble("maxDetectionDistance").let { maxDetectionDistance = it; Log.d(TAG, "maxDetectionDistance = $it m") }
174
190
  config?.getString("apiKey")?.let { apiKey = it; Log.d(TAG, "apiKey = $it") }
175
- config?.getDouble("distanceCorrectionFactor")
176
- .takeIf { config?.hasKey("distanceCorrectionFactor") == true && (it ?: 0.0) > 0 }
177
- ?.let { distanceCorrectionFactor = it; Log.d(TAG, "distanceCorrectionFactor = $it") }
191
+ if (config?.hasKey("distanceCorrectionFactor") == true) {
192
+ val factor = config.getDouble("distanceCorrectionFactor")
193
+ if (factor > 0) { distanceCorrectionFactor = factor; Log.d(TAG, "distanceCorrectionFactor = $factor") }
194
+ }
178
195
  if (config?.hasKey("debug") == true) {
179
196
  debugMode = config.getBoolean("debug")
180
197
  Log.d(TAG, "debugMode = $debugMode")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spotny-sdk",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "Beacon Scanner",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",