Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Bluetooth Low Energy Scanning Issues with scanfilter

When i try to use ScanFilter in BleScan in lollipop its not scanning devices(Only when i pass List of ScanFilter). If i pass only one UUID its working fine. But in the case of Multiple its not working..

 ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_BALANCED).build();
        if (getBluetoothStatus()) {
            mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
            List<ScanFilter> mList=scanFilters(serviceUUIDs);
            mBluetoothLeScanner.startScan(mList, settings, mScanCallback);

        }



     private List<ScanFilter> scanFilters(UUID[] serviceUUIDs) {
                List<ScanFilter> list = new ArrayList<>();
                for (int i = 0; i <serviceUUIDs.length; i++) {
                ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(serviceUUIDs[0].toString())).build();

                    list.add(filter);
                }

          return list;
            }
like image 661
Sibin Avatar asked Jul 30 '15 14:07

Sibin


1 Answers

that's beacause you don't use the variable to go trough on elements.

try this:

ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(serviceUUIDs[i].toStri‌​ng())).build(); 
like image 123
David Avatar answered Nov 06 '22 04:11

David