简体   繁体   中英

Android Bluetooth API connect to multiple devices

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!

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.

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);

是的连接蓝牙服务器插槽中的多个设备可以试试这个

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM