3

I need help. How to set scan timeout for example 10 seconds when i am using rxandroidble.

            scanDisposable = rxBleClient.scanBleDevices(
                new ScanSettings.Builder()
                        .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                        .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
                        .build(),
                new ScanFilter.Builder()
                        .setDeviceAddress("B4:99:4C:34:DC:8B")
                        // add custom filters if needed
                        .build()
            )
                .observeOn(AndroidSchedulers.mainThread())
                .doFinally(this::dispose)
                .subscribe(
                    resultsAdapter::addScanResult, 
                    this::onScanFailure
                );
Dariusz Seweryn
  • 3,212
  • 2
  • 14
  • 21
kosancicivan
  • 55
  • 1
  • 6

1 Answers1

4

If you want to emit an error (TimeoutException) when there is no emission for a specific time then you put a .timeout(int, TimeUnit) after the RxBleClient.scanBleDevices().

If you want to simply complete the scan without any error then you put .take(int, TimeUnit) in the same place as above.

Dariusz Seweryn
  • 3,212
  • 2
  • 14
  • 21