我正在研究 android 和 BLE 设备连接。我想同时连接多个 BLE 设备。如何做到这一点?
最佳答案
您可以从您的 Android 应用程序连接到多个 BLE 设备。
连接:为每个 BLE 设备调用此代码 mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
保存所有 mBluetoothGatt
在列表中。
阅读:在mGattCallback
方法 onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
或 onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)
有gatt
范围。 gatt.getDevice().getAddress()
将为您提供从中接收数据的 BLE 设备的 mac 地址。
写作:使用mBluetoothGatt.getDevice().getAddress()
你总是知道你指向的设备。您可以向其写入命令。在 mGattCallback
方法 onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)
, 参数 gatt
会给你mac地址来确认写入命令。
你可以有一个mGattCallback
为您所有的连接。如果您要区分什么并且不想总是比较 mac 地址,请为每个连接进行一次回调。
This将告诉您您的 Android 设备可以支持多少个连接。
如果您还有疑问,请随时提问。
关于android - 如何通过 Android 应用程序连接多个 BLE 设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47094427/