I am trying to get multiple returns from BLE devices on Android.
I only get a single response.
This used to work on older devices.
My devices is running 5.0.2.
Here is my code:
@TargetApi(Build.VERSION_CODES.M)
private void api21Scan(UUID[] uuids) {
List<ScanFilter> scanFilters = new ArrayList<ScanFilter>();
if (uuids != null) {
for (int i = 0; i < uuids.length; ++i)
scanFilters.add(new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(uuids[i].toString())).build());
}
ScanSettings settings = new ScanSettings.Builder().setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES).build();
ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result)
{
mLeScanCallback.onLeScan(result.getDevice(), result.getRssi(), result.getScanRecord().getBytes());
}
@Override
public void onBatchScanResults(List<ScanResult> results)
{
for (ScanResult sr : results)
{
mLeScanCallback.onLeScan(sr.getDevice(), sr.getRssi(), sr.getScanRecord().getBytes());
}
}
};
if (uuids != null)
mBluetoothAdapter.getBluetoothLeScanner().startScan(scanFilters, settings, scanCallback);
else
mBluetoothAdapter.getBluetoothLeScanner().startScan(null, settings, scanCallback);
}
In LogCat while my app is scanning I do see constant output of lines from TAG: bt-btm where the text says: new address: XX:XX:XX:XX:XX:XX where I see my device over and over.
Why are these scans not getting to my app?
I also have legacy code that uses the deprecated bluetooth adapter startLeScan and it also returns only the first scan of a device.