首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >方法scanBleDevices(UUID))不支持两种类型的服务。

方法scanBleDevices(UUID))不支持两种类型的服务。
EN

Stack Overflow用户
提问于 2016-11-06 08:13:37
回答 1查看 1.3K关注 0票数 0

我遇到了一个问题,方法scanBleDevices(UUID.(过滤器)不能支持发现具有不同UUIDServices的双重设备。

我猜args之间的关系是和,但不是OR。但是我怎样才能得到不同UUIDService的双重设备呢?

下面的代码是我想用uuid 00001801-0000-1000-8000-00805F9B34FB来发现设备,以及使用uuid 6E400001-B5A3-F393-E0A9-E50E24DCCA9E的另一个设备,但是我总是不能用代码获得结果。那么,我如何解决这个问题呢?

代码语言:javascript
复制
scanScription = rxBleClient
            .scanBleDevices(UUID.fromString("00001801-0000-1000-8000-00805F9B34FB"),  UUID.fromString("6E400001-B5A3-F393-E0A9-E50E24DCCA9E"))
            .subscribe(new Action1<RxBleScanResult>() {
        @Override
        public void call(RxBleScanResult rxBleScanResult) {
            if (!bleDeviceHashMap.containsKey(rxBleScanResult.getBleDevice().getMacAddress())) {
                bleDeviceHashMap.put(rxBleScanResult.getBleDevice().getMacAddress(), rxBleScanResult.getBleDevice());
                HashMap<String, String> ble = new HashMap<String, String>();
                ble.put("name", rxBleScanResult.getBleDevice().getName());
                ble.put("address", rxBleScanResult.getBleDevice().getMacAddress());
                bleDevices.add(ble);
                adapter.notifyDataSetChanged();
            }
        }
    });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-07 11:05:34

您可以执行自己的筛选:

代码语言:javascript
复制
final UUIDUtil uuidUtil = new UUIDUtil(); // an util class for parsing advertisement scan record byte[] into UUIDs (part of the RxAndroidBle library)
scanSubscription = rxBleClient
        .scanBleDevices()
        .filter(rxBleScanResult -> {
            final List<UUID> uuids = uuidUtil.extractUUIDs(rxBleScanResult.getScanRecord());
            return uuids.contains(firstUuid) || uuids.contains(secondUuid);
        })
        .subscribe(
            ...
        );

您还可以立即将其分为两个流:

代码语言:javascript
复制
    final UUIDUtil uuidUtil = new UUIDUtil();
    final Observable<RxBleScanResult> sharedScanResultObservable = rxBleClient
            .scanBleDevices()
            .share(); // sharing the scan between two subscriptions

    firstScanSubscription = sharedScanResultObservable
            .filter(rxBleScanResult -> uuidUtil
                    .extractUUIDs(rxBleScanResult.getScanRecord())
                    .contains(firstUuid)) // checking for the first UUID
            .subscribe(
                // reacting for the first type of devices        
            );

    secondScanSubscription = sharedScanResultObservable
            .filter(rxBleScanResult -> uuidUtil
                    .extractUUIDs(rxBleScanResult.getScanRecord())
                    .contains(secondUuid)) // checking for the second UUID
            .subscribe(
                // reacting for the second type of devices
            );
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40447272

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档