android - 找出 Android 蓝牙 LE GATT 配置文件

标签 android bluetooth

我已经实现了查找心率监测器并连接到它的 Android LE 蓝牙示例。然而,这个例子有一个类来定义 GATT 配置文件,如下所示:

 private static HashMap<String, String> attributes = new HashMap();
public static String HEART_RATE_MEASUREMENT = "00002a37-0000-1000-8000-00805f9b34fb";
public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb";

static {
    // Sample Services.
    attributes.put("0000180d-0000-1000-8000-00805f9b34fb", "Heart Rate Service");
    attributes.put("0000180a-0000-1000-8000-00805f9b34fb", "Device Information Service");
    // Sample Characteristics.
    attributes.put(HEART_RATE_MEASUREMENT, "Heart Rate Measurement");
    attributes.put("00002a29-0000-1000-8000-00805f9b34fb", "Manufacturer Name String");
}

public static String lookup(String uuid, String defaultName) {
    String name = attributes.get(uuid);
    return name == null ? defaultName : name;
}

现在,我想做的是更改它,以便该程序可以找到任何带有蓝牙 le 的设备,但我不知道 Google 是如何获得客户端特征配置的心率测量信息的。

最佳答案

蓝牙SIG维护一个“Assigned Numbers”列表,其中包括示例应用中的那些UUID: https://www.bluetooth.com/specifications/assigned-numbers/

虽然 UUID 的长度为 128 位,但为蓝牙 LE 分配的数字被列为 16 位十六进制值,因为低 96 位在一类属性中是一致的。

例如,所有 BLE 特征 UUID 的格式为:

0000XXXX-0000-1000-8000-00805f9b34fb

心率测量特征 UUID 的分配编号被列为 0x2A37,示例代码的开发者可以这样得出:

00002a37-0000-1000-8000-00805f9b34fb

关于android - 找出 Android 蓝牙 LE GATT 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18699251/

相关文章:

ios - 将字符串从 iphone 应用程序传递到 osx 应用程序

安卓 : How to update the selector(StateListDrawable) programmatically

android - 在android中为提示和文本设置不同的字体

java - 使用共享首选项存储数组列表,返回空对象

iOS App 与 PC 程序通信,反之亦然

linux - 在 Fedora 20 上使用 bluez 注册一个 sdp 服务

android - 服务和多线程调用

android - 如何从eclipse检测android物理设备?

ios - 在 iOS 中获取信标的唯一标识符?

ios - 在后台状态卡住http请求