Android Bluetooth API connect to multiple devices
Asked Answered
V

5

14

Is it possible for us to connect multiple devices ? who can share the code for me! This problem has troubled me for a long time! Thanks!

Vizard answered 17/12, 2010 at 7:58 Comment(0)
W
6

I would say that code isn't the problem. The correct implementation is managing a thread for each connection however I have found that the number of devices you can connect to simultaneously is limited based on the phone's implementation of Bluetooth. Bluetooth spec states 7 devices can be connected however I have found android phones that can only handle 1 bluetooth connection while others can handle 6. It would really help the Bluetooth development community if someone from the Android development team could go more in depth here.

Wylie answered 29/6, 2012 at 21:37 Comment(3)
I just wasted a lot of time to discover that the Nexus 7 can only connect 1 BT device, but the Nexus 10 can connect multiple simultaneous devices.Audrieaudris
@SalmanKhakwani, how did you find out how many BT devices could connect to your Nexus 7?Circumnavigate
You can checkout the bluetooth hardware that is being used in the device. You can also check it's number of supported simultaneous connections.Dial
M
4

Yes, you can set up multiple bluetooth connections (at least RFCOMM connections). Just use a alternative thread for you connection, and it would work fine (I guess) See also: http://developer.android.com/resources/samples/BluetoothChat/index.html

Edit, commented layout is unreadable: In the connectThread function, change:

tmp = device.createRfcommSocketToServiceRecord(MY_UUID);

to:

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);
Metagalaxy answered 17/12, 2010 at 9:17 Comment(3)
This sample can not connect multiple device,when I try to connect the third device , it will print io Exception:service discoeryVizard
Hmm, and when you try changing: tmp = device.createRfcommSocketToServiceRecord(MY_UUID); to: Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); tmp = (BluetoothSocket) m.invoke(device, 1); (with the correct try/catches) Do you still get that error? (See answer for readable code..)Metagalaxy
java.io.IOException: Software caused connection abortVizard
G
3

Yes to connect multiple devices in bluetooth server socket in can try this lib

Guttering answered 31/3, 2015 at 2:30 Comment(0)
B
0

Like Barry said, you can connect to multiple devices. Just make a new thread for each connection. You'll want to have a list of the 'ConnectThread's and 'ConnectedThread's that you're keeping track of. So you only have to adapt it for multiple threads (and implementing the ability to select multiple devices, of course). I've done this, and it's not too hard.

If you want to connect to a device and then connect to another (one-by-one using the original menus), then you might have some more work to do.

Ban answered 3/4, 2011 at 20:20 Comment(0)
S
0

For making a multiple connection you have to make separate thread for each and every devices which you want to connect. Each threads have separates methods for read and write data to remote device.

see this link

Android Bluetooth multiple connection issue?

Spraddle answered 3/8, 2011 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.