Skip to content

Commit

Permalink
Added support for Extended Advertising on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakouf authored and qdot committed Dec 21, 2024
1 parent 912db05 commit f7bd8d2
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit f7bd8d2

Please sign in to comment.