从 Notification 获取特征 gatt

Get characteristic gatt from Notification

我将 RxAndroidBle 与 kotlin 结合使用。 到目前为止,我可以设置多个通知并且我正在接收它们。

如何将通知映射到它的特定特征?

到目前为止:

enter code here connectionObserver
            .flatMap { rxBleConnection ->
                rxBleConnection.discoverServices().flatMap { services -> services.getService(ServiceUUID).map(BluetoothGattService::getCharacteristics) }
                        .flatMapObservable { s -> fromIterable(s) }
                        .flatMap { characteristic -> rxBleConnection.setupNotification(characteristic)
                                .flatMap{ notificationObservable -> notificationObservable}}
            }.observeOn(AndroidSchedulers.mainThread())
            .subscribe{notification->notification}

谢谢

对于那些在 kotlin 和 Android 蓝牙上苦苦挣扎的人,经过一些工作我让它工作,所以原始代码看起来像

enter code here  connectionObserver
            .flatMap { rxBleConnection ->
                rxBleConnection.discoverServices().flatMap { services -> services.getService(ServiceUUID).map(BluetoothGattService::getCharacteristics) }
                        .flatMapObservable { s -> fromIterable(s) }
                        .flatMap { characteristic ->
                            rxBleConnection.setupNotification(characteristic)
                                    .flatMap { notificationObservable -> notificationObservable.flatMap { result -> Observable.just(result).zipWith(fromArray(getBytesFromUUID(characteristic.uuid))) } }
                        }

            }.observeOn(AndroidSchedulers.mainThread())
            .subscribe { notification -> onNotificationReceived(notification)
            }