3

我正在研究 android 和 BLE 设备连接。我想同时连接多个 BLE 设备。如何做到这一点?

4

1 回答 1

4

您可以从您的 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地址,请为每个连接进行单个回调。

将告诉您您的 android 设备可以支持多少个连接。

如果您仍有疑问,请随时询问。

于 2017-11-06T10:16:46.083 回答