weliem / blessed-android-coroutines

BLESSED Coroutines, a Bluetooth Low Energy (BLE) library for Android using Kotlin Coroutines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Notify Listeners when Scan Fails

cren90 opened this issue · comments

Currently, the BluetoothCentralManager gets the failure status and logs it, but doesn't send it to listeners:

    private fun sendScanFailed(scanFailure: ScanFailure) {
        currentCallback = null
        currentFilters = null
        scope.launch {
            Logger.e(TAG, "scan failed with error code %d (%s)", scanFailure.value, scanFailure)
         //   bluetoothCentralManagerCallback.onScanFailed(scanFailure)
        }
    }

Looks like it's just a matter of uncommenting line 124.

It is a bit more complex than that. But I added a extra lambda parameter to get scan failures:

        central.scanForPeripheralsWithServices(supportedServices,
            { peripheral, scanResult ->
                Timber.i("Found peripheral '${peripheral.name}' with RSSI ${scanResult.rssi}")
                central.stopScan()
                connectPeripheral(peripheral)
            },
            { scanFailure -> Timber.e("scan failed with reason $scanFailure") })

Released version 0.3.0

...let me know if this works for you