BluetoothGattCallback

This is an important class in the Bluetooth communication which gives an interface to the developer to describe custom tasks performed upon a triggered event. For example, by implementing an onServicesDiscovered method, we can define the tasks to be performed after all the services are discovered. Similarly, onCharacteristicRead can be overridden to perform tasks upon reading a characteristic.

BluetoothGattCallback mBluetoothGattCallback = new BluetoothGattCallback() {     @Override     public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {         super.onConnectionStateChange(gatt, status, newState);     }     @Override     public void onServicesDiscovered(BluetoothGatt gatt, int status) {         super.onServicesDiscovered(gatt, status);     }     @Override     public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {         super.onCharacteristicRead(gatt, characteristic, status);     }     @Override     public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {         super.onCharacteristicWrite(gatt, characteristic, status);     }     @Override     public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {         super.onCharacteristicChanged(gatt, characteristic);     }     @Override     public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {         super.onDescriptorRead(gatt, descriptor, status);     }     @Override     public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {         super.onDescriptorWrite(gatt, descriptor, status);     }     @Override     public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {         super.onReliableWriteCompleted(gatt, status);     }     @Override     public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {         super.onReadRemoteRssi(gatt, rssi, status);     }     @Override     public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {         super.onMtuChanged(gatt, mtu, status);     } };

More detail about how to implement this class in a more practical way can be found later in this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.220.114