当我尝试在 Lollipop 的BleScan中使用ScanFilter时,它不扫描设备(仅当我通过ScanFilter列表时)。如果我只通过一个UUID,它的工作正常。但是在使用Multiple的情况下,它不起作用。

 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;
            }

最佳答案

那是因为您不使用变量来处理元素。
试试这个:

ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(serviceUUIDs[i].toStri‌​ng())).build();

关于带有scanfilter的Android蓝牙低功耗扫描问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31725910/

10-09 12:55