cordova-plugin-bluetoothle icon indicating copy to clipboard operation
cordova-plugin-bluetoothle copied to clipboard

Add whether Bluetooth scan is in traditional mode(ScanSettings.Builder.setLegacy())

Open l0z0y opened this issue 10 months ago • 1 comments

PixPin_2024-03-27_13-19-00 While using the application recently, I encountered an issue where the device couldn't be scanned. After investigating, I found that the device's advertising type is Bluetooth 5 Advertising Extension. Upon consulting the Android documentation, I discovered that the ScanSettings.Builder.setLegacy() method was introduced in Android 26 API.

Link to Android Documentation

setLegacy(false) is a method in ScanSettings.Builder that determines whether the scan operates in "legacy" mode. With Bluetooth 5, a new scanning mode was introduced to support additional features like extended advertising and long data packets. Conversely, "legacy" mode only supports traditional advertising data types and does not accommodate Bluetooth 5's extended advertising.

Hence, when you use setLegacy(false), you're instructing the system not to employ "legacy" mode, but rather to use the new mode, enabling scanning for Bluetooth 5's extended advertisements and other new features.

Based on this understanding, I propose adding a parameter isLegacy() to confirm whether to activate scanning in legacy mode. Below is the code I added:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    boolean isLegacy = obj.optBoolean(keyIsLegacy, true);
    scanSettings.setLegacy(isLegacy);
}

This change allows for flexible configuration of the scan mode, ensuring compatibility and functionality as required.

l0z0y avatar Mar 27 '24 05:03 l0z0y