From dc13281e612bad42327ecbc0767fe6d00f8024a3 Mon Sep 17 00:00:00 2001 From: Jakob Schweisshelm Date: Tue, 12 Nov 2024 15:10:42 +0100 Subject: [PATCH 1/2] fixing build Wrong API on BluetoothAdapter is getting called. Changed it to the according API call getDefaultAdapter() --- .../com/nonpolynomial/btleplug/android/impl/Peripheral.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Peripheral.java b/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Peripheral.java index 160a5de2..256025e4 100644 --- a/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Peripheral.java +++ b/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Peripheral.java @@ -37,7 +37,7 @@ class Peripheral { private CommandCallback commandCallback; public Peripheral(Adapter adapter, String address) { - this.device = BluetoothAdapter.getAdapter().getRemoteDevice(address); + this.device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address); this.adapter = adapter; this.callback = new Callback(); } From e88fd4daa88b806557f7b8c156440aafc5f624d6 Mon Sep 17 00:00:00 2001 From: Jakob Schweisshelm Date: Tue, 12 Nov 2024 15:11:10 +0100 Subject: [PATCH 2/2] Added support for Extended Advertising on Android --- .../btleplug/android/impl/Adapter.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Adapter.java b/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Adapter.java index e2a4332b..d03c8e21 100644 --- a/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Adapter.java +++ b/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Adapter.java @@ -8,6 +8,7 @@ import android.bluetooth.le.ScanFilter.Builder; import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanSettings; +import android.os.Build; import android.os.ParcelUuid; import java.util.ArrayList; @@ -35,9 +36,17 @@ public void startScan(ScanFilter filter) { filters.add(new Builder().setServiceUuid(ParcelUuid.fromString(uuid)).build()); } } - ScanSettings settings = new ScanSettings.Builder() - .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) - .build(); + ScanSettings settings; + if (Build.VERSION.SDK_INT >= 26) { + settings = new ScanSettings.Builder() + .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) + .setLegacy(false) + .build(); + } else { + settings = new ScanSettings.Builder() + .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) + .build(); + } BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner(); if (scanner == null) { throw new RuntimeException("No bluetooth scanner available for adapter");