public abstract class Request
extends java.lang.Object
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.| Modifier and Type | Field and Description |
|---|---|
protected no.nordicsemi.android.ble.CallbackHandler |
handler |
protected no.nordicsemi.android.ble.RequestHandler |
requestHandler |
| Modifier and Type | Method and Description |
|---|---|
Request |
before(BeforeCallback callback)
Sets a callback that will be executed before the execution of this operation starts.
|
static SimpleRequest |
createBond()
Deprecated.
Access to this method will change to package-only.
Use
BleManager.createBond() instead. |
Request |
done(SuccessCallback callback)
Use to set a completion callback.
|
void |
enqueue()
Enqueues the request for asynchronous execution.
|
Request |
fail(FailCallback callback)
Use to set a callback that will be called in case the request has failed.
|
Request |
invalid(InvalidRequestCallback callback)
Use to set a callback that will be called in case the request was invalid, for example
called before the device was connected.
|
static ConnectionPriorityRequest |
newConnectionPriorityRequest(int priority)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.requestConnectionPriority(int) instead. |
static WriteRequest |
newDisableBatteryLevelNotificationsRequest()
Deprecated.
|
static WriteRequest |
newDisableIndicationsRequest(android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.disableNotifications(BluetoothGattCharacteristic) instead. |
static WriteRequest |
newDisableNotificationsRequest(android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.disableNotifications(BluetoothGattCharacteristic) instead. |
static WriteRequest |
newEnableBatteryLevelNotificationsRequest()
Deprecated.
Use
newEnableNotificationsRequest(BluetoothGattCharacteristic) with
BatteryLevelDataCallback from Android BLE Common Library instead. |
static WriteRequest |
newEnableIndicationsRequest(android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.enableIndications(BluetoothGattCharacteristic) instead. |
static WriteRequest |
newEnableNotificationsRequest(android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.enableNotifications(BluetoothGattCharacteristic) instead. |
static MtuRequest |
newMtuRequest(int mtu)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.requestMtu(int) instead. |
static ReadRequest |
newReadBatteryLevelRequest()
Deprecated.
Use
newReadRequest(BluetoothGattCharacteristic) with
BatteryLevelDataCallback from Android BLE Common Library instead. |
static PhyRequest |
newReadPhyRequest()
Deprecated.
Access to this method will change to package-only.
Use
BleManager.readPhy() instead. |
static ReadRequest |
newReadRequest(android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.readCharacteristic(BluetoothGattCharacteristic) instead. |
static ReadRequest |
newReadRequest(android.bluetooth.BluetoothGattDescriptor descriptor)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.readDescriptor(BluetoothGattDescriptor) instead. |
static ReadRssiRequest |
newReadRssiRequest()
Deprecated.
Access to this method will change to package-only.
Use
BleManager.readRssi() instead. |
static SimpleRequest |
newRefreshCacheRequest()
Deprecated.
Access to this method will change to package-only.
Use
BleManager.refreshDeviceCache() instead. |
static PhyRequest |
newSetPreferredPhyRequest(int txPhy,
int rxPhy,
int phyOptions)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.setPreferredPhy(int, int, int) instead. |
static SleepRequest |
newSleepRequest(long delay)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.sleep(long) instead. |
static WaitForValueChangedRequest |
newWaitForIndicationRequest(android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.waitForIndication(BluetoothGattCharacteristic) instead. |
static WaitForValueChangedRequest |
newWaitForNotificationRequest(android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.waitForNotification(BluetoothGattCharacteristic) instead. |
static WriteRequest |
newWriteRequest(android.bluetooth.BluetoothGattCharacteristic characteristic,
byte[] value)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.writeCharacteristic(BluetoothGattCharacteristic, byte[]) instead. |
static WriteRequest |
newWriteRequest(android.bluetooth.BluetoothGattCharacteristic characteristic,
byte[] value,
int writeType)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.writeCharacteristic(BluetoothGattCharacteristic, Data) instead. |
static WriteRequest |
newWriteRequest(android.bluetooth.BluetoothGattCharacteristic characteristic,
byte[] value,
int offset,
int length)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.writeCharacteristic(BluetoothGattCharacteristic, byte[], int, int)
instead. |
static WriteRequest |
newWriteRequest(android.bluetooth.BluetoothGattCharacteristic characteristic,
byte[] value,
int offset,
int length,
int writeType)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.writeCharacteristic(BluetoothGattCharacteristic, byte[], int, int)
instead. |
static WriteRequest |
newWriteRequest(android.bluetooth.BluetoothGattDescriptor descriptor,
byte[] value)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.writeDescriptor(BluetoothGattDescriptor, byte[]) instead. |
static WriteRequest |
newWriteRequest(android.bluetooth.BluetoothGattDescriptor descriptor,
byte[] value,
int offset,
int length)
Deprecated.
Access to this method will change to package-only.
Use
BleManager.writeDescriptor(BluetoothGattDescriptor, byte[], int, int) instead. |
static SimpleRequest |
removeBond()
Deprecated.
Access to this method will change to package-only.
Use
BleManager.removeBond() instead. |
Request |
setHandler(android.os.Handler handler)
Sets the handler that will be used to invoke callbacks.
|
protected no.nordicsemi.android.ble.RequestHandler requestHandler
protected no.nordicsemi.android.ble.CallbackHandler handler
@NonNull public Request setHandler(@NonNull android.os.Handler handler)
BleManager will be used.handler - The handler to invoke callbacks for this request.@Deprecated @NonNull public static SimpleRequest createBond()
BleManager.createBond() instead.@Deprecated @NonNull public static SimpleRequest removeBond()
BleManager.removeBond() instead.
The device will disconnect after calling this method. The success callback will be called
after the device got disconnected, when the BluetoothDevice.getBondState() changes
to BluetoothDevice.BOND_NONE.
@Deprecated @NonNull public static ReadRequest newReadRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic)
BleManager.readCharacteristic(BluetoothGattCharacteristic) instead.characteristic - characteristic to be read.@Deprecated @NonNull public static WriteRequest newWriteRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic, @Nullable byte[] value)
BleManager.writeCharacteristic(BluetoothGattCharacteristic, byte[]) instead.characteristic - characteristic to be written.value - value to be written. The array is copied into another buffer so it's
safe to reuse the array again.@Deprecated @NonNull public static WriteRequest newWriteRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic, @Nullable byte[] value, int writeType)
BleManager.writeCharacteristic(BluetoothGattCharacteristic, Data) instead.characteristic - characteristic to be written.value - value to be written. The array is copied into another buffer so it's
safe to reuse the array again.writeType - write type to be used, one of
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE.@Deprecated @NonNull public static WriteRequest newWriteRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic, @Nullable byte[] value, int offset, int length)
BleManager.writeCharacteristic(BluetoothGattCharacteristic, byte[], int, int)
instead.characteristic - characteristic to be written.value - value to be written. The array is copied into another buffer so it's
safe to reuse the array again.offset - the offset from which value has to be copied.length - number of bytes to be copied from the value buffer.@Deprecated @NonNull public static WriteRequest newWriteRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic, @Nullable byte[] value, int offset, int length, int writeType)
BleManager.writeCharacteristic(BluetoothGattCharacteristic, byte[], int, int)
instead.characteristic - characteristic to be written.value - value to be written. The array is copied into another buffer so it's
safe to reuse the array again.offset - the offset from which value has to be copied.length - number of bytes to be copied from the value buffer.writeType - write type to be used, one of
BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT,
BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE or
BluetoothGattCharacteristic.WRITE_TYPE_SIGNED.@Deprecated @NonNull public static ReadRequest newReadRequest(@Nullable android.bluetooth.BluetoothGattDescriptor descriptor)
BleManager.readDescriptor(BluetoothGattDescriptor) instead.descriptor - descriptor to be read.@Deprecated @NonNull public static WriteRequest newWriteRequest(@Nullable android.bluetooth.BluetoothGattDescriptor descriptor, @Nullable byte[] value)
BleManager.writeDescriptor(BluetoothGattDescriptor, byte[]) instead.descriptor - descriptor to be written.value - value to be written. The array is copied into another buffer so it's safe
to reuse the array again.@Deprecated @NonNull public static WriteRequest newWriteRequest(@Nullable android.bluetooth.BluetoothGattDescriptor descriptor, @Nullable byte[] value, int offset, int length)
BleManager.writeDescriptor(BluetoothGattDescriptor, byte[], int, int) instead.descriptor - descriptor to be written.value - value to be written. The array is copied into another buffer so it's safe
to reuse the array again.offset - the offset from which value has to be copied.length - number of bytes to be copied from the value buffer.@Deprecated @NonNull public static WriteRequest newEnableNotificationsRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic)
BleManager.enableNotifications(BluetoothGattCharacteristic) instead.characteristic - characteristic to have notifications enabled.@Deprecated @NonNull public static WriteRequest newDisableNotificationsRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic)
BleManager.disableNotifications(BluetoothGattCharacteristic) instead.characteristic - characteristic to have notifications disabled.@Deprecated @NonNull public static WriteRequest newEnableIndicationsRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic)
BleManager.enableIndications(BluetoothGattCharacteristic) instead.characteristic - characteristic to have indications enabled.@Deprecated @NonNull public static WriteRequest newDisableIndicationsRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic)
BleManager.disableNotifications(BluetoothGattCharacteristic) instead.characteristic - characteristic to have indications disabled.@Deprecated @NonNull public static WaitForValueChangedRequest newWaitForNotificationRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic)
BleManager.waitForNotification(BluetoothGattCharacteristic) instead.
If the notification should be triggered by another operation (for example writing an
op code), set it with WaitForValueChangedRequest.trigger(Operation).
characteristic - characteristic from which a notification should be received.@Deprecated @NonNull public static WaitForValueChangedRequest newWaitForIndicationRequest(@Nullable android.bluetooth.BluetoothGattCharacteristic characteristic)
BleManager.waitForIndication(BluetoothGattCharacteristic) instead.
If the indication should be triggered by another operation (for example writing an
op code), set it with WaitForValueChangedRequest.trigger(Operation).
characteristic - characteristic from which a notification should be received.@NonNull @Deprecated public static ReadRequest newReadBatteryLevelRequest()
newReadRequest(BluetoothGattCharacteristic) with
BatteryLevelDataCallback from Android BLE Common Library instead.@NonNull @Deprecated public static WriteRequest newEnableBatteryLevelNotificationsRequest()
newEnableNotificationsRequest(BluetoothGattCharacteristic) with
BatteryLevelDataCallback from Android BLE Common Library instead.@NonNull @Deprecated public static WriteRequest newDisableBatteryLevelNotificationsRequest()
newDisableNotificationsRequest(BluetoothGattCharacteristic) instead.@Deprecated @NonNull public static MtuRequest newMtuRequest(int mtu)
BleManager.requestMtu(int) instead.fail(FailCallback) callback will be called.
The target device may reject requested value and set a smaller MTU.mtu - the new MTU. Acceptable values are <23, 517>.@Deprecated @NonNull public static ConnectionPriorityRequest newConnectionPriorityRequest(int priority)
BleManager.requestConnectionPriority(int) instead.ConnectionPriorityRequest.CONNECTION_PRIORITY_HIGH
- Interval: 11.25 -15 ms (Android 6+) and 7.5 - 10 ms (older), latency: 0,
supervision timeout: 20 sec,ConnectionPriorityRequest.CONNECTION_PRIORITY_BALANCED
- Interval: 30 - 50 ms, latency: 0, supervision timeout: 20 sec,ConnectionPriorityRequest.CONNECTION_PRIORITY_LOW_POWER
- Interval: 100 - 125 ms, latency: 2, supervision timeout: 20 sec.fail(FailCallback)
callback will be called.priority - one of: ConnectionPriorityRequest.CONNECTION_PRIORITY_HIGH,
ConnectionPriorityRequest.CONNECTION_PRIORITY_BALANCED,
ConnectionPriorityRequest.CONNECTION_PRIORITY_LOW_POWER.@Deprecated @NonNull public static PhyRequest newSetPreferredPhyRequest(int txPhy, int rxPhy, int phyOptions)
BleManager.setPreferredPhy(int, int, int) instead.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 executed and you will get PHY LE 1M as TX and RX PHY in the callback.
txPhy - preferred transmitter PHY. Bitwise OR of any of
PhyRequest.PHY_LE_1M_MASK, PhyRequest.PHY_LE_2M_MASK,
and PhyRequest.PHY_LE_CODED_MASK.rxPhy - preferred receiver PHY. Bitwise OR of any of
PhyRequest.PHY_LE_1M_MASK, PhyRequest.PHY_LE_2M_MASK,
and PhyRequest.PHY_LE_CODED_MASK.phyOptions - preferred coding to use when transmitting on the LE Coded PHY. Can be one
of PhyRequest.PHY_OPTION_NO_PREFERRED,
PhyRequest.PHY_OPTION_S2 or PhyRequest.PHY_OPTION_S8.@Deprecated @NonNull public static PhyRequest newReadPhyRequest()
BleManager.readPhy() instead.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 executed and you will get PHY LE 1M as TX and RX PHY in the callback.
@Deprecated @NonNull public static ReadRssiRequest newReadRssiRequest()
BleManager.readRssi() instead.@Deprecated @NonNull public static SimpleRequest newRefreshCacheRequest()
BleManager.refreshDeviceCache() instead.BluetoothGatt#refresh() method is not in the
public API (it's hidden, and on Android P it is on a light gray list) it is called
using 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 assumes
some time and waits. After the delay, it will start service discovery and clear the
task queue. When the service discovery finishes, the
BleManagerHandler.isRequiredServiceSupported(BluetoothGatt) and
BleManagerHandler.isOptionalServiceSupported(BluetoothGatt) will
be called and the initialization will be performed as if the device has just connected.
@Deprecated @NonNull public static SleepRequest newSleepRequest(long delay)
BleManager.sleep(long) instead.delay - the delay in milliseconds.@NonNull public Request done(@NonNull SuccessCallback callback)
callback - the callback.@NonNull public Request fail(@NonNull FailCallback callback)
BleManager.connect(BluetoothDevice) was never called), the
invalid(InvalidRequestCallback) will be used instead, as the
BluetoothDevice is not known.
This callback will be ignored if request was executed synchronously, in which case the error will be returned as an exception.
callback - the callback.@NonNull public Request invalid(@NonNull InvalidRequestCallback callback)
callback - the callback.@NonNull public Request before(@NonNull BeforeCallback callback)
callback - the callback.public void enqueue()