j.prashant
j.prashant

Reputation: 77

How to connect multiple BLE devices through android application?

I am working on android and BLE device connectivity. I want to connect multiple BLE devices on same time . How to achieve this ?

Upvotes: 3

Views: 2621

Answers (1)

Sundeep1501
Sundeep1501

Reputation: 1538

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.

Upvotes: 4

Related Questions