I am working with android BLE (Bluetooth Low Energy). I am having trouble in scanning BLE device using startLeScan(UUID[] serviceUuids, BluetoothAdapter.LeScanCallback callback)
method
while startLeScan(BluetoothAdapter.LeScanCallback callback)
is working fine.
When i use filter to scan specific serviceUUIDs , the callback is not executing. I am testing with samsung galaxy s6.
I want to know whether this issue is device specific or there is some bug in scaning function.
I'm pretty sure it's not device specific. First of all as IshArt mentioned you should use startScan from Android 5.0 on.
startScan(List<ScanFilter> filters, ScanSettings settings, ScanCallback callback)
From my experience the implementation of Scanfilters works fine if you go for MAC addresses but other filter setup parameters are problematic:
ScanFilter filter = new ScanFilter.Builder().setDeviceAddress(deviceMacAddress).build();
filters.add(filter);
If that is not an option for you, you can also implement your own filter. If you leave the filters list for the startScan() empty, it ignores all filtering and receives everything. Then in the callback you can write your own method to check whether the result meets your requirements or not.
This is a specific problem I've found with the Samsung Galaxy S6. I use the newer scanner API and only support devices on Android 5.0+. My testing has shown the S4, (haven't tested S5), S7, and S8 all work; I don't know why the S6 has issues.
The workaround it is, lamentably, to just filter manually on mac address after the devices are found.
Update
This fixed my issues above that I was having with the Galaxy S6.
Previously, I was adding two conditions to the same ScanFilter
like this (Kotlin):
ScanFilter.Builder()
.setServiceUuid(BluetoothBlind.Service.ParcelUUID)
.setDeviceAddress(macAddress)
.build()
Changing it to split the conditions into multiple filters fixes it:
ScanFilter.Builder()
.setDeviceAddress(macAddress)
.build()
ScanFilter.Builder()
.setServiceUuid(BluetoothBlind.Service.ParcelUUID)
.build()
The issue with BLE filtered scanning is a known issue. See https://github.com/iDevicesInc/SweetBlue/wiki/Android-BLE-Issues for this and other BLE issues. The conclusion is simple: "You have to scan for all devices and do filtering yourself."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With