Package 

Class RxBleConnectionImpl

    • Method Detail

      • requestConnectionPriority

         Completable requestConnectionPriority(int connectionPriority, long delay, @NonNull() TimeUnit timeUnit)

        Performs a GATT request connection priority operation, which requests a connection parameterupdate on the remote device. NOTE: peripheral may silently decline request.

        Tells Android to request an update of connection interval and slave latency parameters.Using CONNECTION_PRIORITY_HIGH will increase transmission speed andbattery drainage, if accepted by the device, compared to CONNECTION_PRIORITY_BALANCED,while using CONNECTION_PRIORITY_LOW_POWER will cause higher latenciesand save battery, if accepted by the device, compared to CONNECTION_PRIORITY_BALANCED.

        By default connection is balanced.

        NOTE: Till API 26 (8.0) there was no method like `BluetoothGattCallback.onConnectionPriorityChanged()`. It was not possible to knowif the request was successful (accepted by the peripheral). This also causes the need of specifying when the request is consideredfinished (parameter delay and timeUnit). Since API 26 the mentioned callback is hidden, yet possible to use. It is not used toautomatically complete this request due to Android OS changing connection parameters on its own. It is not possible to determinewhich callback is actually finishing the request nor if the Android OS will not change the parameters right after the request.If access to the callback is a must for your implementation you may achieve it by setHiddenNativeCallback via queue and createa custom request connection priority operation.

        As of Lollipop the connection parameters are:* CONNECTION_PRIORITY_BALANCED: min interval 30 ms, max interval 50 ms, slave latency 0* CONNECTION_PRIORITY_HIGH: min interval 7.5 ms, max interval 10ms, slave latency 0* CONNECTION_PRIORITY_LOW_POWER: min interval 100ms, max interval 125 ms, slave latency 2

        Returned completable completes after the specified delay if and only if requestConnectionPriority has returned true.

        Parameters:
        connectionPriority - requested connection priority
        delay - delay after which operation is assumed to be successful (must be shorter than 30 seconds)
        timeUnit - time unit of the delay
      • requestMtu

         Single<Integer> requestMtu(int mtu)

        Performs GATT MTU (Maximum Transfer Unit) request.Timeouts after 10 seconds.

      • getMtu

         int getMtu()

        Get currently negotiated MTU value. On pre-lollipop Android versions it will always return 23.

      • discoverServices

         Single<RxBleDeviceServices> discoverServices(long timeout, @NonNull() TimeUnit timeUnit)

        Performs GATT service discovery and emits discovered results. After service discovery you can walk through android.bluetooth.BluetoothGattServices and BluetoothGattCharacteristics.

        Result of the discovery is cached internally so consecutive calls won't trigger BLE operation and can beconsidered relatively lightweight.Timeouts after specified amount of time.

        Parameters:
        timeout - multiplier of TimeUnit after which the discovery will timeout in case of no return values
        timeUnit - TimeUnit for the timeout
      • setupNotification

         Observable<Observable<Array<byte>>> setupNotification(@NonNull() UUID characteristicUuid, @NonNull() NotificationSetupMode setupMode)

        Setup characteristic notification in order to receive callbacks when given characteristic has been changed. Returned observable willemit Observableonce the notification setup has been completed. It is possible to setup more observables for the samecharacteristic and the lifecycle of the notification will be shared among them.

        Notification is automatically unregistered once this observable is unsubscribed.NOTE: due to stateful nature of characteristics if one will setupIndication() before setupNotification()the notification will not be set up and will emit an BleCharacteristicNotificationOfOtherTypeAlreadySetException

        Parameters:
        characteristicUuid - Characteristic UUID for notification setup.
        setupMode - Configures how the notification is set up.
      • setupNotification

         Observable<Observable<Array<byte>>> setupNotification(@NonNull() BluetoothGattCharacteristic characteristic, @NonNull() NotificationSetupMode setupMode)

        Setup characteristic notification in order to receive callbacks when given characteristic has been changed. Returned observable willemit Observableonce the notification setup has been completed. It is possible to setup more observables for the samecharacteristic and the lifecycle of the notification will be shared among them.

        Notification is automatically unregistered once this observable is unsubscribed.

        NOTE: due to stateful nature of characteristics if one will setupIndication() before setupNotification()the notification will not be set up and will emit an BleCharacteristicNotificationOfOtherTypeAlreadySetException

        The characteristic can be retrieved from com.polidea.rxandroidble2.RxBleDeviceServices emitted from discoverServices

        Parameters:
        characteristic - Characteristic for notification setup.
        setupMode - Configures how the notification is set up.
      • setupIndication

         Observable<Observable<Array<byte>>> setupIndication(@NonNull() UUID characteristicUuid, @NonNull() NotificationSetupMode setupMode)

        Setup characteristic indication in order to receive callbacks when given characteristic has been changed. Returned observable willemit Observableonce the indication setup has been completed. It is possible to setup more observables for the samecharacteristic and the lifecycle of the indication will be shared among them.

        Indication is automatically unregistered once this observable is unsubscribed.

        NOTE: due to stateful nature of characteristics if one will setupNotification() before setupIndication()the indication will not be set up and will emit an BleCharacteristicNotificationOfOtherTypeAlreadySetException

        Parameters:
        characteristicUuid - Characteristic UUID for indication setup.
        setupMode - Configures how the notification is set up.
      • setupIndication

         Observable<Observable<Array<byte>>> setupIndication(@NonNull() BluetoothGattCharacteristic characteristic, @NonNull() NotificationSetupMode setupMode)

        Setup characteristic indication in order to receive callbacks when given characteristic has been changed. Returned observable willemit Observableonce the indication setup has been completed. It is possible to setup more observables for the samecharacteristic and the lifecycle of the indication will be shared among them.

        Indication is automatically unregistered once this observable is unsubscribed.

        NOTE: due to stateful nature of characteristics if one will setupNotification() before setupIndication()the indication will not be set up and will emit an BleCharacteristicNotificationOfOtherTypeAlreadySetException

        The characteristic can be retrieved from com.polidea.rxandroidble2.RxBleDeviceServices emitted from discoverServices

        Parameters:
        characteristic - Characteristic for indication setup.
        setupMode - Configures how the notification is set up.
      • readCharacteristic

         Single<Array<byte>> readCharacteristic(@NonNull() UUID characteristicUuid)

        Performs GATT read operation on a characteristic with given UUID.

        Parameters:
        characteristicUuid - Requested characteristic UUID.
      • writeCharacteristic

         Single<Array<byte>> writeCharacteristic(@NonNull() UUID characteristicUuid, @NonNull() Array<byte> data)

        Performs GATT write operation on a characteristic with given UUID.

        Parameters:
        characteristicUuid - Requested characteristic UUID.
      • queue

         <T> Observable<T> queue(@NonNull() RxBleCustomOperation<T> operation)

        This method requires deep knowledge of RxAndroidBLE internals. Use it only as a last resort if you knowwhat your are doing.

        Queue an operation for future execution. The method accepts a RxBleCustomOperation concrete implementationand will queue it inside connection operation queue. When ready to execute, the Observable returnedby the asObservable will besubscribed to.

        Every event emitted by the Observable returned by asObservable will be forwardedto the Observable returned by this method.

        You must ensure the custom operation's Observable does terminate either via {@code onCompleted} or {@code onError(Throwable)}. Otherwise, the internal queue orchestrator will wait forever foryour Observable to complete. Normal queue processing will be resumed after the Observable returned by asObservable completes.

        The operation will be added to the queue using a NORMAL priority.

        Parameters:
        operation - The custom operation to queue.
      • queue

         <T> Observable<T> queue(@NonNull() RxBleCustomOperation<T> operation, @NonNull() Priority priority)

        This method requires deep knowledge of RxAndroidBLE internals. Use it only as a last resort if you knowwhat your are doing.

        Queue an operation for future execution. The method accepts a RxBleCustomOperation concrete implementationand will queue it inside connection operation queue. When ready to execute, the Observable returnedby the asObservable will besubscribed to.

        Every event emitted by the Observable returned by asObservable will be forwardedto the Observable returned by this method.

        You must ensure the custom operation's Observable does terminate either via {@code onCompleted} or {@code onError(Throwable)}. Otherwise, the internal queue orchestrator will wait forever foryour Observable to complete. Normal queue processing will be resumed after the Observable returned by asObservable completes.

        Parameters:
        operation - The custom operation to queue.
        priority - Priority affected to this operation