Rxandroidble方法scanBleDevices(UUID…筛选器)不支持两种类型的服务

Rxandroidble方法scanBleDevices(UUID…筛选器)不支持两种类型的服务,android,rxandroidble,Android,Rxandroidble,我遇到了一个问题,即scanBleDevices(UUID…filters)方法无法支持发现具有不同UUID服务的两种设备 我猜arg之间的关系是AND,但不是OR。但是,我怎样才能获得具有不同UUIDService的双重设备呢 下面的代码是我想发现uuid00001801-0000-1000-8000-00805F9B34FB的设备和另一个uuid6E400001-B5A3-F393-E0A9-E50E24DCA9E的设备,但我总是无法用代码得到结果。 那么,我该如何解决这个问题呢 scanS

我遇到了一个问题,即scanBleDevices(UUID…filters)方法无法支持发现具有不同UUID服务的两种设备

我猜arg之间的关系是AND,但不是OR。但是,我怎样才能获得具有不同UUIDService的双重设备呢

下面的代码是我想发现uuid
00001801-0000-1000-8000-00805F9B34FB
的设备和另一个uuid
6E400001-B5A3-F393-E0A9-E50E24DCA9E
的设备,但我总是无法用代码得到结果。 那么,我该如何解决这个问题呢

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();
            }
        }
    });
scanscript=rxBleClient
.可扫描设备(UUID.来自字符串(“00001801-0000-1000-8000-00805F9B34FB”)、UUID.来自字符串(“6E400001-B5A3-F393-E0A9-E50E24DCA9E”))
.订阅(新操作1(){
@凌驾
公共作废调用(RXbleCanResult RXbleCanResult){
如果(!bleDeviceHashMap.containsKey(RXbleCanResult.getBleDevice().getMacAddress())){
bleDeviceHashMap.put(rxbleCanResult.getBleDevice().getMacAddress(),rxbleCanResult.getBleDevice());
HashMap ble=新的HashMap();
ble.put(“name”,rxBleScanResult.getBleDevice().getName());
ble.put(“地址”,rxBleScanResult.getBleDevice().getMacAddress());
bleDevices.add(ble);
adapter.notifyDataSetChanged();
}
}
});

您可以执行自己的筛选:

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(
            ...
        );
final UUIDUtil UUIDUtil=new UUIDUtil();//用于将广告扫描记录字节[]解析为UUID(RxAndroidBle库的一部分)的util类
scanSubscription=rxBleClient
.可扫描设备()
.filter(rxBleScanResult->{
最终列表uuids=uuidUtil.extractUUIDs(rxBleScanResult.getScanRecord());
返回uuids.contains(第一个uuid)| uuids.contains(第二个uuid);
})
.订阅(
...
);
您还可以立即将其拆分为两个流:

    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
            );
final UUIDUtil UUIDUtil=new UUIDUtil();
最终可观察的SharedScanResultoServable=RxBlClient
.可扫描设备()
.share();//在两个订阅之间共享扫描
firstScanSubscription=SharedScanSultoServable
.filter(rxBleScanResult->uuidUtil
.extractUUIDs(rxBleScanResult.getScanRecord())
.contains(firstUuid))//正在检查第一个UUID
.订阅(
//对第一类设备作出反应
);
secondScanSubscription=SharedScanSultoServable
.filter(rxBleScanResult->uuidUtil
.extractUUIDs(rxBleScanResult.getScanRecord())
.contains(secondUuid))//正在检查第二个UUID
.订阅(
//对第二类装置作出反应
);

您可以执行自己的筛选:

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(
            ...
        );
final UUIDUtil UUIDUtil=new UUIDUtil();//用于将广告扫描记录字节[]解析为UUID(RxAndroidBle库的一部分)的util类
scanSubscription=rxBleClient
.可扫描设备()
.filter(rxBleScanResult->{
最终列表uuids=uuidUtil.extractUUIDs(rxBleScanResult.getScanRecord());
返回uuids.contains(第一个uuid)| uuids.contains(第二个uuid);
})
.订阅(
...
);
您还可以立即将其拆分为两个流:

    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
            );
final UUIDUtil UUIDUtil=new UUIDUtil();
最终可观察的SharedScanResultoServable=RxBlClient
.可扫描设备()
.share();//在两个订阅之间共享扫描
firstScanSubscription=SharedScanSultoServable
.filter(rxBleScanResult->uuidUtil
.extractUUIDs(rxBleScanResult.getScanRecord())
.contains(firstUuid))//正在检查第一个UUID
.订阅(
//对第一类设备作出反应
);
secondScanSubscription=SharedScanSultoServable
.filter(rxBleScanResult->uuidUtil
.extractUUIDs(rxBleScanResult.getScanRecord())
.contains(secondUuid))//正在检查第二个UUID
.订阅(
//对第二类装置作出反应
);

Wa~o。我得到了它!谢谢你的帮助!!哇~o。我得到了它!谢谢你的帮助!!