android - 获取给定 UUID 的 BluetoothGattCharacteristic

标签 android bluetooth-lowenergy bluetooth-gatt

我想知道如果我有 UUID 并已成功连接到 BLE 设备,检索 BluetoothGattCharacteristic 的最佳方法是什么?例如,见下文。 TIA。

public BluetoothGattCharacteristic retrieveCharacteristic(UUID myUUID) {

    BluetoothGattCharacteristic returnChar;
    BluetoothGattService myService;

    myService = mBluetoothGatt.getService(myUUID);
    returnChar = myService.getCharacteristic(myUUID);
    return returnChar;
}

最佳答案

您需要知道该特性在什么服务中,以便通过 uuid 检索它。如果您不知道哪个服务,您可以使用 https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#getServices() 遍历它们然后使用您的 uuid 检查每个服务的特征。

关于android - 获取给定 UUID 的 BluetoothGattCharacteristic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45269296/

相关文章:

java - 正在寻找一个真正好的地方来学习一些直接的 Java 和 'abstract' 概念来帮助 Android!完整的Java初学者:)

android - 通过蓝牙从android浏览Raspberry Pi的文件系统

ios - CoreBluetooth - 可以多次调用 connectPeripheral

c# - 低功耗蓝牙连接参数更新 - 导致 HRESULT : 0x80070005 (E_ACCESSDENIED))? 的设备或窗口

android - 未通知多个 BluetoothGattCharacteristic

android - 将 URL 中的 HTTP 参数与 Android Intent 过滤器匹配

java - Android iText 阅读 PDF : Difference between iText's Parser and Extraction

android - 无法使用 bluetoothgatt.connect() + android ble 重新连接

javascript - 我可以通过网络蓝牙发送文件吗?

Android 10 BLE 连接问题