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

标签 android bluetooth-lowenergy gatt rxandroidble bluetooth-gatt

我正在研究 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/

相关文章:

Windows 10 蓝牙 Gatt 客户端 ValueChanged 问题

Android BLE 4.3 onDescriptorWrite 在启用特性通知时返回状态 128

java - 带处理程序的顺序倒计时器将无法正确更新 textView

java - textview android的圆角

dbus - BlueZ 5.4 DBus API ConnectProfile GATT 服务 UUID

swift - 使用 React native 框架的 Eddystone 信标扫描

java - API 21 new DatePicker Show Week Number 崩溃

android - 如何在多个 fragment 中设置 SupportActionBar()?

linux - 无法使用“sudo hcidump”创建套接字-权限被拒绝

安卓应用 : Connecting to GATT server using UUIDs