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

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;
@@ -50,13 +52,18 @@ import java.util.UUID;
50
52
  @Permission(
51
53
  alias = "bluetooth",
52
54
  strings = {
53
- Manifest.permission.BLUETOOTH,
54
- Manifest.permission.BLUETOOTH_ADMIN,
55
55
  Manifest.permission.BLUETOOTH_SCAN,
56
56
  Manifest.permission.BLUETOOTH_CONNECT,
57
57
  Manifest.permission.BLUETOOTH_ADVERTISE
58
58
  }
59
59
  ),
60
+ @Permission(
61
+ alias = "legacyBluetooth",
62
+ strings = {
63
+ Manifest.permission.BLUETOOTH,
64
+ Manifest.permission.BLUETOOTH_ADMIN
65
+ }
66
+ ),
60
67
  @Permission(
61
68
  alias = "location",
62
69
  strings = {
@@ -68,7 +75,7 @@ import java.util.UUID;
68
75
  )
69
76
  public class BluetoothLowEnergyPlugin extends Plugin {
70
77
 
71
- private final String pluginVersion = "8.0.2";
78
+ private final String pluginVersion = "8.0.4";
72
79
  private BluetoothManager bluetoothManager;
73
80
  private BluetoothAdapter bluetoothAdapter;
74
81
  private BluetoothLeScanner bluetoothLeScanner;
@@ -310,9 +317,22 @@ public class BluetoothLowEnergyPlugin extends Plugin {
310
317
  deviceObj.put("rssi", result.getRssi());
311
318
 
312
319
  if (result.getScanRecord() != null) {
313
- byte[] manufacturerData = result.getScanRecord().getManufacturerSpecificData(0);
314
- if (manufacturerData != null) {
315
- deviceObj.put("manufacturerData", bytesToHex(manufacturerData));
320
+ SparseArray<byte[]> manufacturerDataArray = result.getScanRecord().getManufacturerSpecificData();
321
+ if (manufacturerDataArray != null && manufacturerDataArray.size() > 0) {
322
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
323
+ for (int i = 0; i < manufacturerDataArray.size(); i++) {
324
+ int companyId = manufacturerDataArray.keyAt(i);
325
+ byte[] data = manufacturerDataArray.valueAt(i);
326
+
327
+ // Append company ID in little-endian order followed by payload to match iOS format.
328
+ output.write(companyId & 0xFF);
329
+ output.write((companyId >> 8) & 0xFF);
330
+ if (data != null) {
331
+ output.write(data, 0, data.length);
332
+ }
333
+ }
334
+
335
+ deviceObj.put("manufacturerData", bytesToHex(output.toByteArray()));
316
336
  }
317
337
 
318
338
  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.4"
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.4",
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",