I am working on android and BLE device connectivity. I want to connect multiple BLE devices on same time . How to achieve this ?
-
https://developers.google.com/nearby/messages/overview this might help – Levon Petrosyan Nov 03 '17 at 11:15
-
This is a bit vague question. One device needs to be a peripheral (advertiser) and another needs to be a client that can connect to the peripheral. What have you tried so far? – Emil Nov 03 '17 at 19:57
1 Answers
You can connect to more than one BLE device from your android application.
CONNECTING: Call this code for each BLE device mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
Save all the mBluetoothGatt
in to list.
READING: In mGattCallback
methods onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
or onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)
has gatt
parameter. gatt.getDevice().getAddress()
will give you the mac address of the BLE device from where you've received the data.
WRITING: Using mBluetoothGatt.getDevice().getAddress()
you always know the device you are pointing to. You can write the command to it. In mGattCallback
method onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status)
, parameter gatt
will give you the mac address to confirm the write command.
You can have single mGattCallback
for all your connections. If you what to differentiate and don't want to always compare mac addresses, go for single callback for each connection.
This will tell you how many connections can your android device can support.
Feel free to ask if you still have doubts.

- 1,510
- 1
- 18
- 28
-
okay, i will try this.. thanks. I will message you if i found any difficulty. – j.prashant Nov 06 '17 at 10:44
-
@j.prashant This is very similar to single ble communication. If you really need an example, give me couple of days. I'll host it on github. – Sundeep1501 Nov 15 '17 at 13:30