Tony Lin
Tony Lin

Reputation: 805

Receive notifications from characteristic

I'm learning android ble api. I can't receive notification from a characteristic that it's protperty is 0x002. So I tried setCharacteristicNotification(mChar, true) and descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) to make onCharacteristicChanged invoked. But it does't work, can anybody help me?

Thanks.

Upvotes: 1

Views: 498

Answers (1)

KikiTheMonk
KikiTheMonk

Reputation: 1015

It seems that 0x02 (Click here to see all the available properties) means that you can only read this characteristic and you cannot enable notifications to it.

To read a characteristic value use the following method:

mBluetoothGatt.ReadCharacteristic(mChar);

and then the

onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)

callback will be called with the updated value of the characteristic. You can then use one or more of the following methods to retrieve it's updated value

ch.getFloatValue(formatType, offset);
ch.getIntValue(formatType, offset);
ch.getStringValue(offset);
ch.getValue();

Upvotes: 2

Related Questions