【发布时间】:2016-12-31 09:40:09
【问题描述】:
我正在使用 BLE 开发一个 android 应用程序。此应用程序的要求是更新具有各种输入的特定硬件中的电压变化。所以我在这个应用程序中启用了 BLE 通知 API。这将在一段时间内以最新的硬件电压通知应用程序。
实施
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
BluetoothGattDescriptor des = characteristic.getDescriptors();
des.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
//Set the value of the descriptor to enable notification
mBluetoothGatt.writeDescriptor(des);
我在 Gatt CallBack 方法的通知值中收到通知
@Override
public void onCharacteristicChanged(BluetoothGatt Gatt, BluetoothGattCharacteristic characteristic) {
Log.w(TAG, "**ACTION_DATA_AVAILABLE**" + characteristic.getUuid());
//Indication or notification was received
broadcastUpdate(BLEConstants.ACTION_DATA_AVAILABLE, characteristic);
//Go broadcast an intent with the characteristic data
}
但我的问题是,我在相同的 Gatt 回调方法中也得到了正常响应。我想在 UI 中以特定方式更新通知。所以我需要将正常响应和通知分开。有没有办法做同样的事情?或者任何识别特定消息的选项来自通知?
【问题讨论】:
标签: java android android-layout android-studio bluetooth-lowenergy