Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/android/BluetoothLePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -1287,7 +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, false);
try {
scanSettings.setLegacy(isLegacy);
} catch (IllegalArgumentException e) {
}
}
//Start the scan with or without service UUIDs
bluetoothAdapter.getBluetoothLeScanner().startScan(scanFilter, scanSettings.build(), scanCallback);
}
Expand Down
5 changes: 5 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down