(java,bluetooth lowenergy,ble)如何通过ble从android设备获取数据
我是BLE(蓝牙低能量)的初学者。我想通过BLE从android设备获取数据 我已经在谷歌的文档中读到了这个特性。 我也已经在谷歌上搜索过了 我的设备没有响应我的请求字节码。 我想这是因为我设置了错误的特征。 因为我想我没有完全理解特征 有人帮我设置正确的特征吗 这里是自定义Uuid(最好在顶部看到添加的图像) 这是我设置的Uuid(java,bluetooth lowenergy,ble)如何通过ble从android设备获取数据,java,bluetooth-lowenergy,Java,Bluetooth Lowenergy,我是BLE(蓝牙低能量)的初学者。我想通过BLE从android设备获取数据 我已经在谷歌的文档中读到了这个特性。 我也已经在谷歌上搜索过了 我的设备没有响应我的请求字节码。 我想这是因为我设置了错误的特征。 因为我想我没有完全理解特征 有人帮我设置正确的特征吗 这里是自定义Uuid(最好在顶部看到添加的图像) 这是我设置的Uuid public final UUID serviceUuid = UUID.fromString("0783b03e-8535-b5a0-7140-a304d
public final UUID serviceUuid = UUID.fromString("0783b03e-8535-b5a0-7140-a304d2495cb7");
public final UUID notifyUuid = UUID.fromString("0783b03e-8535-b5a0-7140-a304d2495cb8");
public final UUID readUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
public final UUID writeUuid = UUID.fromString("0783b03e-8535-b5a0-7140-a304d2495cba");
这是我的密码
BluetoothHandler.java
我通过参考这个网站解决了这个问题。
BluetoothHandler.java
targetGattCharacteristic = targetGattService.getCharacteristic(Define.GetInstance().notifyUuid);
BluetoothGattCharacteristic readGattCharacteristic = targetGattService.getCharacteristic(Define.GetInstance().notifyUuid);
if (readGattCharacteristic != null) {
mBleService.setCharacteristicNotification(readGattCharacteristic, true);
} else {
callInterface();
return;
}
(BluetoothService.java)
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
boolean enabled) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
BluetoothGattDescriptor gD = new BluetoothGattDescriptor(UUID.fromString(Define.GetInstance().readUuid.toString()), BluetoothGattDescriptor.PERMISSION_WRITE | BluetoothGattDescriptor.PERMISSION_READ);
characteristic.addDescriptor(gD);
if (Define.GetInstance().notifyUuid.equals(characteristic.getUuid())) {
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString(Define.GetInstance().readUuid.toString()));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
}
}