Android 安卓蓝牙获取心率测量
我想得到“A&D UA-651BLE”设备的人力资源管理价值。 这是写入该设备数据表以获取HRM值的内容:Android 安卓蓝牙获取心率测量,android,android-bluetooth,android-ble,Android,Android Bluetooth,Android Ble,我想得到“A&D UA-651BLE”设备的人力资源管理价值。 这是写入该设备数据表以获取HRM值的内容: 将应用程序设置为配对模式以开始扫描 按照每个说明手册开始A&D BLE设备的配对 在配对模式下,应用程序应设置时间和日期以及任何其他设备设置 到A&D可编程设备。配对成功后,A&D BLE设备在屏幕上显示“结束” 进行测量并完成测量,然后a&D BLE设备启动BLE 与广告有关。应用程序以适当的间隔开始扫描,以便 该应用程序会尽快捕获A&D设备的广告 在初始连接或配对时,应用程序将“2”设
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
boolean enabled) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
// This is specific to Heart Rate Measurement.
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
}
}
这是读取数据的方法:
final byte[] data = characteristic.getValue();
if (data != null && data.length > 0) {
final StringBuilder stringBuilder = new StringBuilder(data.length);
for(byte byteChar : data)
stringBuilder.append(String.format("%02X ", byteChar));
Log.e("HRM value",stringBuilder.toString());
dataComposition.put(characteristic.getUuid().toString(),stringBuilder.toString());
intent.putExtra(EXTRA_DATA,dataComposition);
}
问题是这段代码不返回任何数据 有一种方法可以做到这一点,最简单的方法是克隆、构建并将其与您自己的进行比较。如果您无法发现差异/问题,只需部署两个应用程序并逐步完成两组代码。拥有一些已知的工作代码也有助于排除人力资源管理功能不正常的可能性 你有没有这样的例子,我用同样的设备试了一下,但我无法获得信息
public String response() {
if (mConnected) {
mBluetoothLeService.readCharacteristic(characteristica);
byte response[] = characteristica.getValue();
String respuesta = ReadBytes(response);
mBluetoothLeService.disconnect();
return respuesta;
} else {
return null;
}
}
感谢这个链接,我看到了这个项目,问题是我正在使用的设备需要写操作,而这个项目没有显示我们可以写值和描述符