Package 

Class Request


  • 
    public abstract class Request
    
                        

    On Android, when multiple BLE operations needs to be done, it is required to wait for a proper BluetoothGattCallback callback before calling another operation. In order to make BLE operations easier the BleManager allows to enqueue a request containing all data necessary for a given operation. Requests are performed one after another until the queue is empty.

    • Method Detail

      • setHandler

        @NonNull() Request setHandler(@Nullable() Handler handler)

        Sets the handler that will be used to invoke callbacks. By default, the handler set in BleManager will be used.

        If set to null, the callbacks will be invoked immediately on the BLE looper.

        Parameters:
        handler - The handler to invoke callbacks for this request.
      • removeBond

        @Deprecated()@NonNull() static SimpleRequest removeBond()

        Creates a new request that will remove the bonding information from the Android device.This is done using reflections and may not work on all devices.

        The device will disconnect after calling this method. The success callback will be calledafter the device got disconnected, when the getBondState changesto BOND_NONE.

      • newReadRequest

        @Deprecated()@NonNull() static ReadRequest newReadRequest(@Nullable() BluetoothGattCharacteristic characteristic)

        Creates new Read Characteristic request. The request will not be executed if givencharacteristic is null or does not have READ property.After the operation is complete a proper callback will be invoked.

        Parameters:
        characteristic - characteristic to be read.
      • newWriteRequest

        @Deprecated()@NonNull() static WriteRequest newWriteRequest(@Nullable() BluetoothGattCharacteristic characteristic, @Nullable() Array<byte> value)

        Creates new Write Characteristic request. The request will not be executed if givencharacteristic is null or does not have WRITE property.After the operation is complete a proper callback will be invoked.

        Parameters:
        characteristic - characteristic to be written.
        value - value to be written.
      • newWriteRequest

        @Deprecated()@NonNull() static WriteRequest newWriteRequest(@Nullable() BluetoothGattCharacteristic characteristic, @Nullable() Array<byte> value, @IntRange(from = 0) int offset, @IntRange(from = 0) int length)

        Creates new Write Characteristic request. The request will not be executed if givencharacteristic is null or does not have WRITE property.After the operation is complete a proper callback will be invoked.

        Parameters:
        characteristic - characteristic to be written.
        value - value to be written.
        offset - the offset from which value has to be copied.
        length - number of bytes to be copied from the value buffer.
      • newWriteRequest

        @Deprecated()@NonNull() static WriteRequest newWriteRequest(@Nullable() BluetoothGattDescriptor descriptor, @Nullable() Array<byte> value, @IntRange(from = 0) int offset, @IntRange(from = 0) int length)

        Creates new Write Descriptor request. The request will not be executed if given descriptoris null. After the operation is complete a proper callback will be invoked.

        Parameters:
        descriptor - descriptor to be written.
        value - value to be written.
        offset - the offset from which value has to be copied.
        length - number of bytes to be copied from the value buffer.
      • newWaitForNotificationRequest

        @Deprecated()@NonNull() static WaitForValueChangedRequest newWaitForNotificationRequest(@Nullable() BluetoothGattCharacteristic characteristic)

        Creates new Wait For Notification request. The request will not be executed if givencharacteristic is null, does not have NOTIFY property or the CCCD.After the operation is complete a proper callback will be invoked.

        If the notification should be triggered by another operation (for example writing anop code), set it with trigger.

        Parameters:
        characteristic - characteristic from which a notification should be received.
      • newWaitForIndicationRequest

        @Deprecated()@NonNull() static WaitForValueChangedRequest newWaitForIndicationRequest(@Nullable() BluetoothGattCharacteristic characteristic)

        Creates new Wait For Indication request. The request will not be executed if givencharacteristic is null, does not have INDICATE property or the CCCD.After the operation is complete a proper callback will be invoked.

        If the indication should be triggered by another operation (for example writing anop code), set it with trigger.

        Parameters:
        characteristic - characteristic from which a notification should be received.
      • newReadBatteryLevelRequest

        @NonNull()@Deprecated() static ReadRequest newReadBatteryLevelRequest()

        Creates new Read Battery Level request. The first found Battery Level characteristic valuefrom the first found Battery Service. If any of them is not found, or the characteristicdoes not have the READ property this operation will not execute.

      • newEnableBatteryLevelNotificationsRequest

        @NonNull()@Deprecated() static WriteRequest newEnableBatteryLevelNotificationsRequest()

        Creates new Enable Notifications on the first found Battery Level characteristic from thefirst found Battery Service. If any of them is not found, or the characteristic does nothave the NOTIFY property this operation will not execute.

      • newDisableBatteryLevelNotificationsRequest

        @NonNull()@Deprecated() static WriteRequest newDisableBatteryLevelNotificationsRequest()

        Creates new Disable Notifications on the first found Battery Level characteristic from thefirst found Battery Service. If any of them is not found, or the characteristic does nothave the NOTIFY property this operation will not execute.

      • newMtuRequest

        @Deprecated()@NonNull() static MtuRequest newMtuRequest(@IntRange(from = 23, to = 517) int mtu)

        Requests new MTU (Maximum Transfer Unit). This is only supported on Android Lollipop or newer.On older platforms the request will enqueue, but will fail to execute and fail callback will be called.The target device may reject requested value and set a smaller MTU.

        Parameters:
        mtu - the new MTU.
      • newSetPreferredPhyRequest

        @Deprecated()@NonNull() static PhyRequest newSetPreferredPhyRequest(int txPhy, int rxPhy, int phyOptions)

        Requests the change of preferred PHY for this connections.

        PHY LE 2M and PHY LE Coded are supported only on Android Oreo or newer.You may safely request other PHYs on older platforms, but the request will not be executedand you will get PHY LE 1M as TX and RX PHY in the callback.

        Parameters:
        txPhy - preferred transmitter PHY.
        rxPhy - preferred receiver PHY.
        phyOptions - preferred coding to use when transmitting on the LE Coded PHY.
      • newReadPhyRequest

        @Deprecated()@NonNull() static PhyRequest newReadPhyRequest()

        Reads the current PHY for this connections.

        PHY LE 2M and PHY LE Coded are supported only on Android Oreo or newer.You may safely read PHY on older platforms, but the request will not be executedand you will get PHY LE 1M as TX and RX PHY in the callback.

      • newRefreshCacheRequest

        @Deprecated()@NonNull() static SimpleRequest newRefreshCacheRequest()

        Refreshes the device cache. As the refresh method is not in thepublic API (it's hidden, and on Android P it is on a light gray list) it is calledusing reflections and may be removed in some future Android release or on some devices.

        There is no callback indicating when the cache has been cleared. This library assumessome time and waits. After the delay, it will start service discovery and clear thetask queue. When the service discovery finishes, the isRequiredServiceSupported and isOptionalServiceSupported willbe called and the initialization will be performed as if the device has just connected.

      • done

        @NonNull() Request done(@NonNull() SuccessCallback callback)

        Use to set a completion callback. The callback will be invoked when the operation hasfinished successfully unless the request was executed synchronously, in which case thiscallback will be ignored.

        Parameters:
        callback - the callback.
      • fail

        @NonNull() Request fail(@NonNull() FailCallback callback)

        Use to set a callback that will be called in case the request has failed.If the target device wasn't set before executing this request(connect was never called), the invalid will be used instead, as the BluetoothDevice is not known.

        This callback will be ignored if request was executed synchronously, in which casethe error will be returned as an exception.

        Parameters:
        callback - the callback.
      • invalid

        @NonNull() Request invalid(@NonNull() InvalidRequestCallback callback)

        Use to set a callback that will be called in case the request was invalid, for examplecalled before the device was connected.This callback will be ignored if request was executed synchronously, in which casethe error will be returned as an exception.

        Parameters:
        callback - the callback.
      • enqueue

         void enqueue()

        Enqueues the request for asynchronous execution.