【发布时间】:2017-11-03 11:13:49
【问题描述】:
我正在研究 android 和 BLE 设备连接。我想同时连接多个 BLE 设备。如何做到这一点?
【问题讨论】:
-
这是一个有点模糊的问题。一个设备需要是外围设备(广告商),而另一个设备需要是可以连接到外围设备的客户端。到目前为止,您尝试过什么?
标签: android bluetooth-lowenergy gatt rxandroidble bluetooth-gatt
我正在研究 android 和 BLE 设备连接。我想同时连接多个 BLE 设备。如何做到这一点?
【问题讨论】:
标签: android bluetooth-lowenergy gatt rxandroidble bluetooth-gatt
您可以从您的 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 会告诉你你的安卓设备可以支持多少个连接。
如果您仍有疑问,请随时询问。
【讨论】: