lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

BluetoothGattCallback

public abstract class BluetoothGattCallback
extends Object

java.lang.Object
   ↳ android.bluetooth.BluetoothGattCallback


This abstract class is used to implement BluetoothGatt callbacks.

Summary

Public constructors

BluetoothGattCallback()

Public methods

void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)

Callback triggered as a result of a remote characteristic notification.

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

Callback reporting the result of a characteristic read operation.

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)

Callback reporting the result of a descriptor read operation.

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(int, int, int), 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 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.

Inherited methods

Public constructors

BluetoothGattCallback

added in API level 18
public BluetoothGattCallback ()

Public methods

onCharacteristicChanged

added in API level 18
public void onCharacteristicChanged (BluetoothGatt gatt, 
                BluetoothGattCharacteristic characteristic)

Callback triggered as a result of a remote characteristic notification.

Parameters
gatt BluetoothGatt: GATT client the characteristic is associated with

characteristic BluetoothGattCharacteristic: Characteristic that has been updated as a result of a remote notification event.

onCharacteristicRead

added in API level 18
public void onCharacteristicRead (BluetoothGatt gatt, 
                BluetoothGattCharacteristic characteristic, 
                int status)

Callback reporting the result of a characteristic read operation.

Parameters
gatt BluetoothGatt: GATT client invoked BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic)

characteristic BluetoothGattCharacteristic: Characteristic that was read from the associated remote device.

status int: BluetoothGatt.GATT_SUCCESS if the read operation was completed successfully.

onCharacteristicWrite

added in API level 18
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 invoked BluetoothGatt.writeCharacteristic(BluetoothGattCharacteristic)

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.

onConnectionStateChange

added in API level 18
public void onConnectionStateChange (BluetoothGatt gatt, 
                int status, 
                int newState)

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

Parameters
gatt BluetoothGatt: GATT client

status int: Status of the connect or disconnect operation. BluetoothGatt.GATT_SUCCESS if the operation succeeds.

newState int: Returns the new connection state. Can be one of BluetoothProfile.STATE_DISCONNECTED or BluetoothProfile.STATE_CONNECTED

onDescriptorRead

added in API level 18
public void onDescriptorRead (BluetoothGatt gatt, 
                BluetoothGattDescriptor descriptor, 
                int status)

Callback reporting the result of a descriptor read operation.

Parameters
gatt BluetoothGatt: GATT client invoked BluetoothGatt.readDescriptor(BluetoothGattDescriptor)

descriptor BluetoothGattDescriptor: Descriptor that was read from the associated remote device.

status int: BluetoothGatt.GATT_SUCCESS if the read operation was completed successfully

onDescriptorWrite

added in API level 18
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(BluetoothGattDescriptor)

descriptor BluetoothGattDescriptor: Descriptor that was writte to the associated remote device.

status int: The result of the write operation BluetoothGatt.GATT_SUCCESS if the operation succeeds.

onMtuChanged

added in API level 21
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(int) function, or in response to a connection event.

Parameters
gatt BluetoothGatt: GATT client invoked BluetoothGatt.requestMtu(int)

mtu int: The new MTU size

status int: BluetoothGatt.GATT_SUCCESS if the MTU has been changed successfully

onPhyRead

added in API level 26
public void onPhyRead (BluetoothGatt gatt, 
                int txPhy, 
                int rxPhy, 
                int status)

Callback triggered as result of BluetoothGatt.readPhy()

Parameters
gatt BluetoothGatt: GATT client

txPhy int: the transmitter PHY in use. One of BluetoothDevice.PHY_LE_1M, BluetoothDevice.PHY_LE_2M, and BluetoothDevice.PHY_LE_CODED.

rxPhy int: the receiver PHY in use. One of BluetoothDevice.PHY_LE_1M, BluetoothDevice.PHY_LE_2M, and BluetoothDevice.PHY_LE_CODED.

status int: Status of the PHY read operation. BluetoothGatt.GATT_SUCCESS if the operation succeeds.

onPhyUpdate

added in API level 26
public void onPhyUpdate (BluetoothGatt gatt, 
                int txPhy, 
                int rxPhy, 
                int status)

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

Parameters
gatt BluetoothGatt: GATT client

txPhy int: the transmitter PHY in use. One of BluetoothDevice.PHY_LE_1M, BluetoothDevice.PHY_LE_2M, and BluetoothDevice.PHY_LE_CODED.

rxPhy int: the receiver PHY in use. One of BluetoothDevice.PHY_LE_1M, BluetoothDevice.PHY_LE_2M, and BluetoothDevice.PHY_LE_CODED.

status int: Status of the PHY update operation. BluetoothGatt.GATT_SUCCESS if the operation succeeds.

onReadRemoteRssi

added in API level 18
public void onReadRemoteRssi (BluetoothGatt gatt, 
                int rssi, 
                int status)

Callback reporting the RSSI for a remote device connection. This callback is triggered in response to the BluetoothGatt.readRemoteRssi() function.

Parameters
gatt BluetoothGatt: GATT client invoked BluetoothGatt.readRemoteRssi()

rssi int: The RSSI value for the remote device

status int: BluetoothGatt.GATT_SUCCESS if the RSSI was read successfully

onReliableWriteCompleted

added in API level 18
public void onReliableWriteCompleted (BluetoothGatt gatt, 
                int status)

Callback invoked when a reliable write transaction has been completed.

Parameters
gatt BluetoothGatt: GATT client invoked BluetoothGatt.executeReliableWrite()

status int: BluetoothGatt.GATT_SUCCESS if the reliable write transaction was executed successfully

onServicesDiscovered

added in API level 18
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.