Android BLE device scan with filter is not working

Akhilesh Kumar picture Akhilesh Kumar · Dec 3, 2015 · Viewed 18.5k times · Source

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.

Answer

Chris picture Chris · Dec 4, 2015

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.