Android : Android Bluetooth Low Energy - Using ScanFilters

on Tuesday, March 24, 2015


I'm currently working on an Android app for Bluetooth Low Energy scanning. In Android 5.0 the option for ScanFilters was introduced. It is working in general, but the number of filters seems to be limited (?)


If I use more than 13 different filters, I cannot find any BLE devices anymore and I get notifications that the app has stopped, even though it continues in the background without finding anything. I don't get warnings or error messages. If I use less filters than 13, everything works just fine. Also the addresses used for filtering do not cause the problem. It comes down to the maximum number as it seems...


The code: The scan runs in an own Thread:



[...]
BluetoothLeScanner myScanner = myBluetoothAdapter.getBluetoothLeScanner();
ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();


//The list for the filters
filters = new ArrayList<>();

//mac adresses of ble devices
String[] filterlist = {
"D4:B4:C8:7E:D1:35",
"C8:86:3A:91:0C:0C",
"FD:49:FD:36:04:B4",
"E9:91:4A:42:AC:3B",
//... some 20 more addresses
};

//adding the mac adresses to the filters list
for (int i=0; i< filterlist.length ; i++) {
ScanFilter filter = new ScanFilter.Builder().setDeviceAddress(filterlist[i]).build();
filters.add(filter);
Log.v("Filter: "," "+ filters.get(i).getDeviceAddress());
}



[...]
while (scanning) {
final ScanCallback callback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
Log.v("Callback","in the callback");
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
Log.v("ScanTask", "Some error occurred");
});

[...]

//starting the scan with the filters
myScanner.startScan(filters, settings, callback);

//creating some delay and then end the scan
Thread.sleep(myScanTime);
myScanner.stopScan(callback);

[...]
}


There seems to be no problem within the code. But why is there a limit on the maximum number of filters? Can someone push me into the right direction or knows a workaround?


0 comments:

Post a Comment