Gatt Server로 부터 알림 받기

특성 값이 변경되면 Gatt 서버에 알림을 요청할 수 있습니다.

1
2
3
4
5
gatt.setCharacteristicNotification(characteristic, true);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);

서버의 모든 알림은 BluetoothGattCallback의 onCharacteristicChanged 메소드로 수신됩니다.

1
2
3
4
5
    @Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
super.onCharacteristicChanged(gatt, characteristic);
byte[] newValue = characteristic.getValue();
}
공유하기