Android BLE - 确定特征的存储值类型

标签 android bluetooth bluetooth-lowenergy

我的问题是缺乏确定值类型的能力,读取的 BLE 特性一直在存储。根据蓝牙规范。 https://www.bluetooth.com/specifications/assigned-numbers/format-types这些类型由标准预定义,因此 GATT 客户端应该能够读取它们。

我的应用程序试图创建通用的 GATT 客户端,该客户端能够读取任何服务及其存储的任何特征。为此,我必须有一些通用的方法来读取特征的类型,这样我才能正确地读取它。为此,我缺少 BLE API,这将允许这样做

我认为这里提出了类似的问题:How to get BluetoothGattCharacteristic value format type?但问题没有得到回答。

不幸的是,当前的解决方法是将蓝牙特征中指定的 UUID 映射到存储值的类型。这解决了很多日常案例,但仍然不足以创建完全通用的 GATT 客户端。

最佳答案

好的,我找到了答案。对于遇到类似问题的人来说,答案不在 BLE android API 中,而在蓝牙 GATT 规范中。

事实证明,一些描述符是强制性的,其中之一是特征表示格式,在此处指定:

https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml

在那里我们可以找到“硬编码值类型”,它是 8 位值和枚举,它将这个值表示为类型。根据这个值,我们可以推断出特征的值类型并正确读取它。

关于Android BLE - 确定特征的存储值类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40672805/

相关文章:

Android - 从 WebView 绘制到 PDF Canvas

android - Flutter App 卡在 Android 启动器屏幕上

c++ - Windows 上的蓝牙低功耗低速率?

bluetooth-lowenergy - 微:bit Bluetooth Low Energy Hacking Persistence (High School Internship Project)

android - 在蓝牙关闭的情况下识别 Android/Kotlin 上的 BLE 设备

android - SQLite 查询性能

android - 如何在android项目中构建模块?

android - 是否可以通过编程方式将 BluetoothDevice 与 android 配对?

bluetooth - 什么语言/库最适合 BLE 连接?

android - Android 4.4 设备可以充当 iBeacon 吗?