如何通过Android应用程序连接多个BLE设备?

时间:2017-11-03 11:13:49

标签: android bluetooth-lowenergy gatt rxandroidble bluetooth-gatt

我正在研究Android和BLE设备连接。我想在同一时间连接多个BLE设备。怎么做到这一点?

1 个答案:

答案 0 :(得分:3)

您可以从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设备可以支持多少个连接。

随时问你是否还有疑问。

相关问题