java - 如何将数据传输到连接的蓝牙 LE 设备

标签 java android bluetooth hex bluetooth-lowenergy

我使用以下说明和示例连接到蓝牙 LE 设备: https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#getService(java.util.UUID)

https://github.com/googlesamples/android-BluetoothLeGatt

但我不知道如何将数据(十六进制代码)发送到 BLE 设备, 谁能帮我? 下面的代码是否将数据发送到设备:

BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
int hexaCode =Integer.parseInt("7c",16);
descriptor.setValue( 
ByteBuffer.allocate(4).putInt(hexaCode).array());
mBluetoothGatt.writeDescriptor(descriptor);

最佳答案

BLE 仅接收服务数据。服务可以是自定义的或 BLE 标准。ON 设备连接发现所有 Ble 服务并找出该设备上的所有可用服务(具有 UUID 和功能)。您可以下载 Nordic Semiconductors nRF connect 应用程序以更好地使用BLE读写的理解

关于java - 如何将数据传输到连接的蓝牙 LE 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47880718/

相关文章:

java - InputStream.read() 在我的缓冲区中丢失或添加了一个值 - 这是怎么回事?

java - 实现PATCH操作Play - Java

java - Android 如果矩形包含触摸坐标,则添加到数组中,给出奇怪的输出

java - 从 Windows 为 Java 创建 native OSX 可执行文件

java - 使用多个 View 以编程方式/动态创建 LinearLayout

android - 针对 Android 中的特定运营商

java - 在 Android Studio 的 Java 中解析 JSON 的问题

android - Android 与其他设备之间的蓝牙 SPP、UUID 和 PIN 问题

bluetooth - 获取Android手机支持的蓝牙版本?(5或4.x)

java - 强制 debian 打包中的 java 版本