代码之家  ›  专栏  ›  技术社区  ›  j.prashant

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

  •  3
  • j.prashant  · 技术社区  · 7 年前

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

    1 回复  |  直到 7 年前
        1
  •  4
  •   Sundeep1501    7 年前

    您可以从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) 参数 关贸总协定 将为您提供mac地址以确认写入命令。

    你可以有一个 mGattCallback 为您的所有连接。如果你想区分什么,又不想总是比较mac地址,那么就对每个连接进行一次回调。

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

    如果你还有疑问,尽管问。