我已经实现了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是如何获得客户端特征配置的心率测量信息的。
发布于 2014-05-31 21:47:19
除了@Godfrey Duke的答案之外,下面是我用来提取UUID的有效位的方法:
private static int getAssignedNumber(UUID uuid) {
// Keep only the significant bits of the UUID
return (int) ((uuid.getMostSignificantBits() & 0x0000FFFF00000000L) >> 32);
}
用法示例:
// See https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.heart_rate.xml
private static final int GATT_SERVICE_HEART_RATE = 0x180D;
(...)
for (BluetoothGattService service : services) {
if (getAssignedNumber(service.getUuid()) == GATT_SERVICE_HEART_RATE) {
// Found heart rate service
onHeartRateServiceFound(service);
found = true;
break;
}
}
发布于 2013-09-29 02:39:45
下面是gatt回调的页面:https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html
您需要使用BluetoothGatt.discoverServices();
然后在回调onServicesDiscovered(...)中我认为你需要useBluetoothGatt.getServices();
https://stackoverflow.com/questions/18699251
复制相似问题