2016-11-06 3 views
0

scanBleDevices(UUID ... filters)メソッドが異なるUUIDServicesを持つ2種類のデバイスを検出できないという問題が発生しました。Rxandroidble - メソッドscanBleDevices(UUID ... filters)が2種類のサービスをサポートしていません

argsの関係はANDですが、ORではないと思います。しかし、UUIDServiceの異なる2種類のデバイスをどうやって得ることができますか?

下のコードは、uuid 00001801-0000-1000-8000-00805F9B34FBのデバイスとuuid 6E400001-B5A3-F393-E0A9-E50E24DCCA9Eのデバイスを検出したいのですが、私はいつもそのコードで結果を得ることができません。 どうすれば問題を解決できますか?

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

答えて

2

独自のフィルタリングを行うことができます。

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(); 
    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 
      ); 
+0

ワ〜0を。わかった !ご協力いただきありがとうございます!! – Botasky

関連する問題