我正在BLE (蓝牙)的Android上工作。我已经通过谷歌找到了信息。看起来,Android可以通过使用多个BluetoothGatt连接到multiple BLE device,如下面的伪代码。
我有多个BLE设备,。我认为我需要首先定义多个BluetoothGatt参数。
private BluetoothGatt mBluetoothGattA = null,
mBluetoothGattB = null , mBluetoothGattC = null;第一个BLE设备连接。
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address_A);
mBluetoothGattA = device.connectGatt(this, false, mGattCallback);尝试连接到第二个BLE设备。
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address_B);
mBluetoothGattB = device.connectGatt(this, false, mGattCallback);我说的对吗?如果我连接到6个BLE设备,是否应该定义6个BluetoothGatt参数?
是否有一种智能的方式连接到多个BLE设备?
发布于 2017-11-23 15:02:17
不是必要的多个BluetoothGattCallback。意外地,我用相同的BluetoothGattCallback连接两个BLE设备,工作正常。
在BluetoothGattCallback中,您必须知道发送数据的设备的地址。
例如,您可以使用:
gatt.getDevice().getAddress();希望能帮上忙
发布于 2015-09-29 20:38:44
您将通过为每个BluetoothGattCallback创建每个BLE设备(现在最多7)来处理每个BLE设备。例如:
private final BluetoothGattCallback oneGattcallback = new BluetoothGattCallback() ... private final BluetoothGattCallback twoGattcallback = new BluetoothGattCallback() ...
然后试着像这样连接mBluetoothGattA = deviceA.connectGatt(this, false, oneGattcallback );和mBluetoothGattB = deviceB.connectGatt(this, false, twoGattcallback );。你会发现很多例子处理一个连接,只需要为多个连接开发更多。
https://stackoverflow.com/questions/26754534
复制相似问题