androidbluetooth-lowenergyrx-java2rxandroidble

RxAndroidBle on Android - requesting MTU and then reading from connection


In RxAndroidBle, I want to set the MTU and then read a characteristic from the connection.

device
    .establishConnection(false)
    .flatMapSingle(conn -> conn.requestMtu(64))
    .flatMapSingle(mtu -> <?>);

I'd like to then do a conn.readCharacteristic, but I don't have a reference to conn after raising the MTU.

I'm fairly new to RxJava2 so maybe I'm missing something at a conceptual level. Could anybody provide any insight here?


Solution

  • You can do it like that

    device
        .establishConnection(false)
        .flatMapSingle(conn -> conn.requestMtu(64)
            .flatMap(mtu -> conn.readCharacteristic()))