I'm using RxAndroidBle library v 1.4.1. I'd like to scan every few seconds while being connected to a device. The problem is that when I stop the scan (I do not want to scan all the time, just every few seconds) it closes the connection to the device.
rxBleClient.scanBleDevices(
newScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)
.build(),
new ScanFilter.Builder()
.setServiceUuid("xyz")
.build()
)
.buffer(SCANNING_WINDOW_SECONDS, TimeUnit.SECONDS)
.first()
.repeatWhen(observable -> observable.delay(INTERVAL, TimeUnit.SECONDS));
I know that this behavior is documented "scanBleDevices() - this Observable when unsubscribed closes/cleans up internal resources (i.e. finishes scan, closes a connection, disables notifications)"
Is there any workaround? Or do I have to waste the battery and scan all the time while being connected or do not scan at all?
EDIT The problem occurs only on some devices - eg. Asus Zenfone T100J.
scanDevices()
.doOnNext(device -> {
if(disconnected && device!=null){connect();}
})