I am developing an android app for handling BLE devices. I need to connect two BLE device at the same time and read/write characteristics,services from/to the device at the same time. How can I do this? Is it needed separate GATT instance and callback for each device? How to do this?
Asked
Active
Viewed 2,086 times
-2
-
1review https://stackoverflow.com/questions/21237093/android-4-3-how-to-connect-to-multiple-bluetooth-low-energy-devices – Sahil Mar 18 '19 at 06:54
-
1Possible duplicate of [Android 4.3: How to connect to multiple Bluetooth Low Energy devices](https://stackoverflow.com/questions/21237093/android-4-3-how-to-connect-to-multiple-bluetooth-low-energy-devices) – dbrumann Mar 18 '19 at 15:16
1 Answers
3
It's very simple. Just execute connectGatt one time for every device, which will then give you one BluetoothGatt object per device. The callback object can be the same, or a separate instance per device, it's up to you, although I guess it's easier if you have one instance per device.

Emil
- 16,784
- 2
- 41
- 52
-
I used device address to connect that two device. Is there any other possible way? – Neetha Mar 18 '19 at 09:10
-
-
1As long as you have a BluetoothDevice object, you can make a GATT connection to it. You can get it either using Bluetooth device address (which can sometimes be problematic since the API misses the random / public address type bit) or by a scan. You can have one outstanding GATT operation at a time, per BluetoothGatt object, so yes you can read / write characteristics to both devices simultaneously. If your code doesn't work, feel free to post it and point out your issues. – Emil Mar 18 '19 at 17:47