BluetoothGattCallback  |  API reference  |  Android Developers


public abstract class BluetoothGattCallback
extends Object



This abstract class is used to implement BluetoothGatt callbacks.

Summary

Public constructors

BluetoothGattCallback()

Public methods

void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value)

Callback triggered as a result of a remote characteristic notification.

void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)

This method was deprecated in API level 33. Use BluetoothGattCallback.onCharacteristicChanged(BluetoothGatt,BluetoothGattCharacteristic,byte[]) as it is memory safe by providing the characteristic value at the time of notification.

void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value, int status)

Callback reporting the result of a characteristic read operation.

void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)

This method was deprecated in API level 33. Use BluetoothGattCallback.onCharacteristicRead(BluetoothGatt,BluetoothGattCharacteristic,byte[],int) as it is memory safe

void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)

Callback indicating the result of a characteristic write operation.

void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)

Callback indicating when GATT client has connected/disconnected to/from a remote GATT server.

void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status, byte[] value)

Callback reporting the result of a descriptor read operation.

void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status)

This method was deprecated in API level 33. Use BluetoothGattCallback.onDescriptorRead(BluetoothGatt,BluetoothGattDescriptor,int,byte[]) as it is memory safe by providing the descriptor value at the time it was read.

void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status)

Callback indicating the result of a descriptor write operation.

void onMtuChanged(BluetoothGatt gatt, int mtu, int status)

Callback indicating the MTU for a given device connection has changed.

void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status)

Callback triggered as result of BluetoothGatt.readPhy

void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status)

Callback triggered as result of BluetoothGatt.setPreferredPhy, or as a result of remote device changing the PHY.

void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status)

Callback reporting the RSSI for a remote device connection.

void onReliableWriteCompleted(BluetoothGatt gatt, int status)

Callback invoked when a reliable write transaction has been completed.

void onServiceChanged(BluetoothGatt gatt)

Callback indicating service changed event is received

Receiving this event means that the GATT database is out of sync with the remote device.

void onServicesDiscovered(BluetoothGatt gatt, int status)

Callback invoked when the list of remote services, characteristics and descriptors for the remote device have been updated, ie new services have been discovered.

void onSubrateChange(BluetoothGatt gatt, int subrateMode, int status)

Callback indicating LE connection's subrate parameters have changed.

Inherited methods

From class java.lang.Object

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public constructors

BluetoothGattCallback

public BluetoothGattCallback ()

Public methods

onCharacteristicChanged

public void onCharacteristicChanged (BluetoothGatt gatt, 
                BluetoothGattCharacteristic characteristic, 
                byte[] value)

Callback triggered as a result of a remote characteristic notification. Note that the value within the characteristic object may have changed since receiving the remote characteristic notification, so check the parameter value for the value at the time of notification.

Parameters
gatt BluetoothGatt: GATT client the characteristic is associated with.
This value cannot be null.
characteristic BluetoothGattCharacteristic: Characteristic that has been updated as a result of a remote notification event.
This value cannot be null.
value byte: notified characteristic value.
This value cannot be null.

onCharacteristicRead

public void onCharacteristicRead (BluetoothGatt gatt, 
                BluetoothGattCharacteristic characteristic, 
                byte[] value, 
                int status)

Callback reporting the result of a characteristic read operation.

Parameters
gatt BluetoothGatt: GATT client invoked BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic)
This value cannot be null.
characteristic BluetoothGattCharacteristic: Characteristic that was read from the associated remote device.
This value cannot be null.
value byte: the value of the characteristic.
This value cannot be null.
status int: BluetoothGatt.GATT_SUCCESS if the read operation was completed successfully.

onCharacteristicWrite

public void onCharacteristicWrite (BluetoothGatt gatt, 
                BluetoothGattCharacteristic characteristic, 
                int status)

Callback indicating the result of a characteristic write operation.

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.

Parameters
gatt BluetoothGatt: GATT client that invoked BluetoothGatt.writeCharacteristic(BluetoothGattCharacteristic,byte[],int)
characteristic BluetoothGattCharacteristic: Characteristic that was written to the associated remote device.
status int: The result of the write operation BluetoothGatt.GATT_SUCCESS if the operation succeeds.

onDescriptorRead

public void onDescriptorRead (BluetoothGatt gatt, 
                BluetoothGattDescriptor descriptor, 
                int status, 
                byte[] value)

Callback reporting the result of a descriptor read operation.

Parameters
gatt BluetoothGatt: GATT client invoked BluetoothGatt.readDescriptor
This value cannot be null.
descriptor BluetoothGattDescriptor: Descriptor that was read from the associated remote device.
This value cannot be null.
status int: BluetoothGatt.GATT_SUCCESS if the read operation was completed successfully
value byte: the descriptor value at the time of the read operation.
This value cannot be null.

onDescriptorWrite

public void onDescriptorWrite (BluetoothGatt gatt, 
                BluetoothGattDescriptor descriptor, 
                int status)

Callback indicating the result of a descriptor write operation.

Parameters
gatt BluetoothGatt: GATT client invoked BluetoothGatt.writeDescriptor
descriptor BluetoothGattDescriptor: Descriptor that was written to the associated remote device.
status int: The result of the write operation BluetoothGatt.GATT_SUCCESS if the operation succeeds.

onMtuChanged

public void onMtuChanged (BluetoothGatt gatt, 
                int mtu, 
                int status)

Callback indicating the MTU for a given device connection has changed.

This callback is triggered in response to the BluetoothGatt.requestMtu function, or in response to a connection event.

Parameters
gatt BluetoothGatt: GATT client invoked BluetoothGatt.requestMtu
mtu int: The new MTU size
status int: BluetoothGatt.GATT_SUCCESS if the MTU has been changed successfully

onServiceChanged

public void onServiceChanged (BluetoothGatt gatt)

Callback indicating service changed event is received

Receiving this event means that the GATT database is out of sync with the remote device. BluetoothGatt.discoverServices should be called to re-discover the services.

Parameters
gatt BluetoothGatt: GATT client involved.
This value cannot be null.

onServicesDiscovered

public void onServicesDiscovered (BluetoothGatt gatt, 
                int status)

Callback invoked when the list of remote services, characteristics and descriptors for the remote device have been updated, ie new services have been discovered.

Parameters
gatt BluetoothGatt: GATT client invoked BluetoothGatt.discoverServices
status int: BluetoothGatt.GATT_SUCCESS if the remote device has been explored successfully.