From 33ae4bcb17b9f28978d7c1c44cfacdd84ca48ead Mon Sep 17 00:00:00 2001 From: Norah Tromp <80421914+l0z0y@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:54:06 +0800 Subject: [PATCH 1/3] Update index.d.ts add isLegacy options --- types/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/index.d.ts b/types/index.d.ts index 638d062..cb5e4cb 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -703,6 +703,11 @@ declare namespace BluetoothlePlugin { callbackType?: BluetoothCallbackType, /** True/false to show only connectable devices, rather than all devices ever seen, defaults to false (Windows)*/ isConnectable?: boolean + /** Used to set whether scanning is in "legacy" mode. In Bluetooth 5, a new scanning mode is introduced to support more + functions and features, such as extended advertising, long data packets, etc. The "legacy" mode only supports + traditional advertising data types and does not support Bluetooth 5's extended advertising. + */ + isLegacy?:boolean } interface ConnectionParams{ From 18ecdcc7ef8133ee73dd4008dc2a9717f6ce5d01 Mon Sep 17 00:00:00 2001 From: Norah Tromp <80421914+l0z0y@users.noreply.github.com> Date: Wed, 27 Mar 2024 12:00:10 +0800 Subject: [PATCH 2/3] Update BluetoothLePlugin.java add isLegacy option --- src/android/BluetoothLePlugin.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/android/BluetoothLePlugin.java b/src/android/BluetoothLePlugin.java index ffea195..f2be33c 100644 --- a/src/android/BluetoothLePlugin.java +++ b/src/android/BluetoothLePlugin.java @@ -105,6 +105,7 @@ public class BluetoothLePlugin extends CordovaPlugin { private final String keyMatchMode = "matchMode"; private final String keyMatchNum = "matchNum"; private final String keyCallbackType = "callbackType"; + private final String keyIsLegacy = "isLegacy"; private final String keyAdvertisement = "advertisement"; private final String keyUuid = "uuid"; private final String keyService = "service"; @@ -1288,6 +1289,12 @@ private synchronized void startScanAction(JSONArray args, CallbackContext callba } } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + boolean isLegacy = obj.optBoolean(keyIsLegacy, true); + scanSettings.setLegacy(isLegacy); + } + //Start the scan with or without service UUIDs bluetoothAdapter.getBluetoothLeScanner().startScan(scanFilter, scanSettings.build(), scanCallback); } From fe3d3fb505fb85ea540eaf34df377013c4a525b8 Mon Sep 17 00:00:00 2001 From: Norah Tromp <80421914+l0z0y@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:41:22 +0800 Subject: [PATCH 3/3] Update BluetoothLePlugin.java Add error handling --- src/android/BluetoothLePlugin.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/android/BluetoothLePlugin.java b/src/android/BluetoothLePlugin.java index f2be33c..ec35f09 100644 --- a/src/android/BluetoothLePlugin.java +++ b/src/android/BluetoothLePlugin.java @@ -1288,13 +1288,13 @@ private synchronized void startScanAction(JSONArray args, CallbackContext callba } catch (java.lang.IllegalArgumentException e) { } } - - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - boolean isLegacy = obj.optBoolean(keyIsLegacy, true); - scanSettings.setLegacy(isLegacy); - } - + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + boolean isLegacy = obj.optBoolean(keyIsLegacy, false); + try { + scanSettings.setLegacy(isLegacy); + } catch (IllegalArgumentException e) { + } + } //Start the scan with or without service UUIDs bluetoothAdapter.getBluetoothLeScanner().startScan(scanFilter, scanSettings.build(), scanCallback); }