protected abstract static class BleManager.BleManagerGattCallback
extends java.lang.Object
BleManager.getGattCallback(). It is responsible for all GATT operations.| Modifier | Constructor and Description |
|---|---|
protected |
BleManagerGattCallback() |
| Modifier and Type | Method and Description |
|---|---|
android.bluetooth.BluetoothDevice |
getBluetoothDevice() |
byte[] |
getCharacteristicValue(android.bluetooth.BluetoothGattCharacteristic serverCharacteristic)
Returns the value of the server characteristic.
|
byte[] |
getDescriptorValue(android.bluetooth.BluetoothGattDescriptor serverDescriptor)
Returns the value of the server descriptor.
|
protected java.util.Deque<Request> |
initGatt(android.bluetooth.BluetoothGatt gatt)
Deprecated.
Use
initialize() instead. |
protected void |
initialize()
This method should set up the request queue needed to initialize the profile.
|
protected boolean |
isOptionalServiceSupported(android.bluetooth.BluetoothGatt gatt)
This method should return
true when the gatt device supports the
optional services. |
protected abstract boolean |
isRequiredServiceSupported(android.bluetooth.BluetoothGatt gatt)
This method should return
true when the gatt device supports the
required services. |
protected void |
onBatteryValueReceived(android.bluetooth.BluetoothGatt gatt,
int value)
Deprecated.
Use
ReadRequest.with(DataReceivedCallback) and
BatteryLevelDataCallback from BLE-Common-Library instead. |
protected void |
onCharacteristicIndicated(android.bluetooth.BluetoothGatt gatt,
android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Use
ReadRequest.with(DataReceivedCallback) instead. |
protected void |
onCharacteristicNotified(android.bluetooth.BluetoothGatt gatt,
android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Use
ReadRequest.with(DataReceivedCallback) instead. |
protected void |
onCharacteristicRead(android.bluetooth.BluetoothGatt gatt,
android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Use
ReadRequest.with(DataReceivedCallback) instead. |
protected void |
onCharacteristicWrite(android.bluetooth.BluetoothGatt gatt,
android.bluetooth.BluetoothGattCharacteristic characteristic)
Deprecated.
Use
WriteRequest.done(SuccessCallback) instead. |
protected void |
onConnectionUpdated(android.bluetooth.BluetoothGatt gatt,
int interval,
int latency,
int timeout)
Deprecated.
|
protected void |
onDescriptorRead(android.bluetooth.BluetoothGatt gatt,
android.bluetooth.BluetoothGattDescriptor descriptor)
Deprecated.
Use
ReadRequest.with(DataReceivedCallback) instead. |
protected void |
onDescriptorWrite(android.bluetooth.BluetoothGatt gatt,
android.bluetooth.BluetoothGattDescriptor descriptor)
Deprecated.
Use
WriteRequest and SuccessCallback instead. |
protected abstract void |
onDeviceDisconnected()
This method should nullify all services and characteristics of the device.
|
protected void |
onDeviceReady()
Called when the initialization queue is complete.
|
protected void |
onManagerReady()
Called each time the task queue gets cleared.
|
protected void |
onMtuChanged(android.bluetooth.BluetoothGatt gatt,
int mtu)
Deprecated.
Use
MtuRequest.with(MtuCallback) instead. |
protected void |
onServerReady(android.bluetooth.BluetoothGattServer server)
In this method the manager should get references to server characteristics and descriptors
that will use.
|
void |
post(java.lang.Runnable r) |
void |
postDelayed(java.lang.Runnable r,
long delayMillis) |
void |
removeCallbacks(java.lang.Runnable r) |
public android.bluetooth.BluetoothDevice getBluetoothDevice()
@Nullable
public final byte[] getCharacteristicValue(@NonNull
android.bluetooth.BluetoothGattCharacteristic serverCharacteristic)
serverCharacteristic - The characteristic to get value of.@Nullable
public final byte[] getDescriptorValue(@NonNull
android.bluetooth.BluetoothGattDescriptor serverDescriptor)
serverDescriptor - The descriptor to get value of.public void post(@NonNull
java.lang.Runnable r)
public void postDelayed(@NonNull
java.lang.Runnable r,
long delayMillis)
public void removeCallbacks(@NonNull
java.lang.Runnable r)
protected abstract boolean isRequiredServiceSupported(@NonNull
android.bluetooth.BluetoothGatt gatt)
true when the gatt device supports the
required services.gatt - the gatt device with services discoveredTrue when the device has the required service.protected boolean isOptionalServiceSupported(@NonNull
android.bluetooth.BluetoothGatt gatt)
true when the gatt device supports the
optional services. The default implementation returns false.gatt - the gatt device with services discoveredTrue when the device has the optional service.@Deprecated protected java.util.Deque<Request> initGatt(@NonNull android.bluetooth.BluetoothGatt gatt)
initialize() instead.This method is called when the services has been discovered and the device is supported (has required service).
gatt - the gatt device with services discoveredprotected void initialize()
Request.fail(FailCallback).
This method is called from the main thread when the services has been discovered and the device is supported (has required service).
Remember to call Request.enqueue() for each request.
A sample initialization should look like this:
@Override
protected void initialize() {
requestMtu(MTU)
.with((device, mtu) -> {
...
})
.enqueue();
setNotificationCallback(characteristic)
.with((device, data) -> {
...
});
enableNotifications(characteristic)
.done(device -> {
...
})
.fail((device, status) -> {
...
})
.enqueue();
}
protected void onServerReady(@NonNull
android.bluetooth.BluetoothGattServer server)
isRequiredServiceSupported(BluetoothGatt) returned true.
The references obtained in this method should be released in onDeviceDisconnected().
This method is called only when the server was set by
BleManager.useServer(BleServerManager) and opened using BleServerManager.open().
server - The GATT Server instance. Use BluetoothGattServer.getService(UUID) to
obtain service instance.protected void onDeviceReady()
protected void onManagerReady()
protected abstract void onDeviceDisconnected()
@Deprecated
protected void onCharacteristicRead(@NonNull
android.bluetooth.BluetoothGatt gatt,
@NonNull
android.bluetooth.BluetoothGattCharacteristic characteristic)
ReadRequest.with(DataReceivedCallback) instead.gatt - GATT clientcharacteristic - Characteristic that was read from the associated remote device.@Deprecated
protected void onCharacteristicWrite(@NonNull
android.bluetooth.BluetoothGatt gatt,
@NonNull
android.bluetooth.BluetoothGattCharacteristic characteristic)
WriteRequest.done(SuccessCallback) instead.If this callback is invoked while a reliable write transaction is in progress, the value of the characteristic represents the value reported by the remote device. An application should compare this value to the desired value to be written. If the values don't match, the application must abort the reliable write transaction.
gatt - GATT clientcharacteristic - Characteristic that was written to the associated remote device.@Deprecated
protected void onDescriptorRead(@NonNull
android.bluetooth.BluetoothGatt gatt,
@NonNull
android.bluetooth.BluetoothGattDescriptor descriptor)
ReadRequest.with(DataReceivedCallback) instead.gatt - GATT clientdescriptor - Descriptor that was read from the associated remote device.@Deprecated
protected void onDescriptorWrite(@NonNull
android.bluetooth.BluetoothGatt gatt,
@NonNull
android.bluetooth.BluetoothGattDescriptor descriptor)
WriteRequest and SuccessCallback instead.If this callback is invoked while a reliable write transaction is in progress, the value of the characteristic represents the value reported by the remote device. An application should compare this value to the desired value to be written. If the values don't match, the application must abort the reliable write transaction.
gatt - GATT clientdescriptor - Descriptor that was written to the associated remote device.@Deprecated
protected void onBatteryValueReceived(@NonNull
android.bluetooth.BluetoothGatt gatt,
int value)
ReadRequest.with(DataReceivedCallback) and
BatteryLevelDataCallback from BLE-Common-Library instead.
This method will not be called if BleManager.readBatteryLevel() and
BleManager.enableBatteryLevelNotifications() were overridden.
gatt - GATT clientvalue - the battery value in percent@Deprecated
protected void onCharacteristicNotified(@NonNull
android.bluetooth.BluetoothGatt gatt,
@NonNull
android.bluetooth.BluetoothGattCharacteristic characteristic)
ReadRequest.with(DataReceivedCallback) instead.gatt - GATT clientcharacteristic - Characteristic from which the notification came.@Deprecated
protected void onCharacteristicIndicated(@NonNull
android.bluetooth.BluetoothGatt gatt,
@NonNull
android.bluetooth.BluetoothGattCharacteristic characteristic)
ReadRequest.with(DataReceivedCallback) instead.gatt - GATT clientcharacteristic - Characteristic from which the indication came.@Deprecated
protected void onMtuChanged(@NonNull
android.bluetooth.BluetoothGatt gatt,
int mtu)
MtuRequest.with(MtuCallback) instead.gatt - GATT clientmtu - the new MTU (Maximum Transfer Unit)@Deprecated
protected void onConnectionUpdated(@NonNull
android.bluetooth.BluetoothGatt gatt,
int interval,
int latency,
int timeout)
ConnectionPriorityRequest.with(ConnectionPriorityCallback) instead.gatt - GATT client.interval - Connection interval used on this connection, 1.25ms unit.
Valid range is from 6 (7.5ms) to 3200 (4000ms).latency - Slave latency for the connection in number of connection events.
Valid range is from 0 to 499.timeout - Supervision timeout for this connection, in 10ms unit.
Valid range is from 10 (0.1s) to 3200 (32s).