扫描过滤器的Android蓝牙低功耗扫描问题

时间:2015-07-30 14:02:30

标签: android bluetooth-lowenergy android-bluetooth

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

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

1 个答案:

答案 0 :(得分:8)

这是因为你没有使用变量去元素。

试试这个:

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