@capgo/capacitor-bluetooth-low-energy 8.0.2 → 8.0.3

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.
@@ -28,6 +28,7 @@ import android.os.Handler;
28
28
  import android.os.Looper;
29
29
  import android.os.ParcelUuid;
30
30
  import android.provider.Settings;
31
+ import android.util.SparseArray;
31
32
  import androidx.annotation.RequiresPermission;
32
33
  import androidx.core.app.ActivityCompat;
33
34
  import com.getcapacitor.JSArray;
@@ -38,6 +39,7 @@ import com.getcapacitor.PluginMethod;
38
39
  import com.getcapacitor.annotation.CapacitorPlugin;
39
40
  import com.getcapacitor.annotation.Permission;
40
41
  import com.getcapacitor.annotation.PermissionCallback;
42
+ import java.io.ByteArrayOutputStream;
41
43
  import java.util.ArrayList;
42
44
  import java.util.HashMap;
43
45
  import java.util.List;
@@ -68,7 +70,7 @@ import java.util.UUID;
68
70
  )
69
71
  public class BluetoothLowEnergyPlugin extends Plugin {
70
72
 
71
- private final String pluginVersion = "8.0.2";
73
+ private final String pluginVersion = "8.0.3";
72
74
  private BluetoothManager bluetoothManager;
73
75
  private BluetoothAdapter bluetoothAdapter;
74
76
  private BluetoothLeScanner bluetoothLeScanner;
@@ -310,9 +312,22 @@ public class BluetoothLowEnergyPlugin extends Plugin {
310
312
  deviceObj.put("rssi", result.getRssi());
311
313
 
312
314
  if (result.getScanRecord() != null) {
313
- byte[] manufacturerData = result.getScanRecord().getManufacturerSpecificData(0);
314
- if (manufacturerData != null) {
315
- deviceObj.put("manufacturerData", bytesToHex(manufacturerData));
315
+ SparseArray<byte[]> manufacturerDataArray = result.getScanRecord().getManufacturerSpecificData();
316
+ if (manufacturerDataArray != null && manufacturerDataArray.size() > 0) {
317
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
318
+ for (int i = 0; i < manufacturerDataArray.size(); i++) {
319
+ int companyId = manufacturerDataArray.keyAt(i);
320
+ byte[] data = manufacturerDataArray.valueAt(i);
321
+
322
+ // Append company ID in little-endian order followed by payload to match iOS format.
323
+ output.write(companyId & 0xFF);
324
+ output.write((companyId >> 8) & 0xFF);
325
+ if (data != null) {
326
+ output.write(data, 0, data.length);
327
+ }
328
+ }
329
+
330
+ deviceObj.put("manufacturerData", bytesToHex(output.toByteArray()));
316
331
  }
317
332
 
318
333
  List<ParcelUuid> serviceUuids = result.getScanRecord().getServiceUuids();
@@ -422,6 +422,13 @@ extension BluetoothLowEnergy: CBCentralManagerDelegate {
422
422
 
423
423
  if let manufacturerData = advertisementData[CBAdvertisementDataManufacturerDataKey] as? Data {
424
424
  device["manufacturerData"] = manufacturerData.map { String(format: "%02x", $0) }.joined()
425
+ } else if let manufacturerDict = advertisementData[CBAdvertisementDataManufacturerDataKey] as? [NSNumber: Data],
426
+ let entry = manufacturerDict.first {
427
+ var data = Data()
428
+ var companyId = entry.key.uint16Value.littleEndian
429
+ withUnsafeBytes(of: &companyId) { data.append(contentsOf: $0) }
430
+ data.append(entry.value)
431
+ device["manufacturerData"] = data.map { String(format: "%02x", $0) }.joined()
425
432
  }
426
433
 
427
434
  if let serviceUUIDs = advertisementData[CBAdvertisementDataServiceUUIDsKey] as? [CBUUID] {
@@ -5,7 +5,7 @@ import CoreBluetooth
5
5
  // swiftlint:disable type_body_length file_length
6
6
  @objc(BluetoothLowEnergyPlugin)
7
7
  public class BluetoothLowEnergyPlugin: CAPPlugin, CAPBridgedPlugin {
8
- private let pluginVersion: String = "8.0.2"
8
+ private let pluginVersion: String = "8.0.3"
9
9
  public let identifier = "BluetoothLowEnergyPlugin"
10
10
  public let jsName = "BluetoothLowEnergy"
11
11
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-bluetooth-low-energy",
3
- "version": "8.0.2",
3
+ "version": "8.0.3",
4
4
  "description": "Bluetooth Low Energy (BLE) plugin for Capacitor with support for scanning, connecting, reading, writing, and notifications.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",