简体   繁体   中英

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM