@Override
public final void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
final String data = ParserUtils.parse(characteristic);
if (isBatteryLevelCharacteristic(characteristic)) {
Logger.i(mLogSession, "Notification received from " + characteristic.getUuid() + ", value: " + data);
final int batteryValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
Logger.a(mLogSession, "Battery level received: " + batteryValue + "%");
mCallbacks.onBatteryValueReceived(batteryValue);
} else {
final BluetoothGattDescriptor cccd = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
final boolean notifications = cccd == null || cccd.getValue() == null || cccd.getValue().length != 2 || cccd.getValue()[0] == 0x01;
if (notifications) {
Logger.i(mLogSession, "Notification received from " + characteristic.getUuid() + ", value: " + data);
onCharacteristicNotified(gatt, characteristic);
} else { // indications
Logger.i(mLogSession, "Indication received from " + characteristic.getUuid() + ", value: " + data);
onCharacteristicIndicated(gatt, characteristic);
}
}
}
BleManager.java 文件源码
java
阅读 55
收藏 0
点赞 0
评论 0
项目:Android-DFU-App
作者:
评论列表
文章目录