我想知道如果我有 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/