获得BluetoothGattCharacteristic给定UUID
问题描述:
我想知道如果我有UUID并已成功连接到BLE设备,检索BluetoothGattCharacteristic的最佳方法是什么?例如,见下文。 TIA。获得BluetoothGattCharacteristic给定UUID
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检查每个服务的特征。
非常感谢! – user3286543