Android bluetooth api connect to multiple devices at the same time

Showing 1-10 of 10 messages
Android bluetooth api connect to multiple devices at the same time 枫儿 12/18/10 6:25 AM
It is possible to connect simultaneously to multiple bluetooth devices?
Re: Android bluetooth api connect to multiple devices at the same time James 12/19/10 11:28 PM
of course you can,
Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time 枫儿 12/20/10 12:37 AM
could you share me your code?Thanks!

2010/12/20 James <0304...@163.com>
of course you can,

On Dec 18, 9:25 am, 苗鹏 <mp870...@gmail.com> wrote:
> It is possible to connect simultaneously to multiple bluetooth devices?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-d...@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: Android bluetooth api connect to multiple devices at the same time Morrison Chang 12/20/10 9:39 PM
Look at http://code.google.com/p/apps-for-android/
Specifically the code for BTClickLinkCompete for a sample of Bluetooth
connectivity.
http://code.google.com/p/apps-for-android/source/browse/#svn%2Ftrunk%2FBTClickLinkCompete

I think the air hockey sample supports 4 other devices along with the
server device.

-Morrison

On Dec 20, 3:37 am, 苗鹏 <mp870...@gmail.com> wrote:
> could you share me your code?Thanks!
>
> 2010/12/20 James <030440...@163.com>
>
>
>
>
>
>
>
> > of course you can,
>
> > On Dec 18, 9:25 am, 苗鹏 <mp870...@gmail.com> wrote:
> > > It is possible to connect simultaneously to multiple bluetooth devices?
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-d...@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscribe@googlegroups.com<android-developers%2Bunsubs cr...@googlegroups.com>
Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time 枫儿 12/20/10 10:26 PM
I will have a try! Thanks !

2010/12/21 Morrison Chang <morriso...@gmail.com>

Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time 枫儿 12/22/10 6:17 PM
I looked at  the FBTClickLinkCompete'source,
 for (int i = 0; i < Connection.MAX_SUPPORTED && myBSock == null; i++) {
                for (int j = 0; j < 3 && myBSock == null; j++) {
                    myBSock = getConnectedSocket(myBtServer, mUuid.get(i));
                    if (myBSock == null) {
                        try {
                            Thread.sleep(200);
                        } catch (InterruptedException e) {
                            Log.e(TAG, "InterruptedException in connect", e);
                        }
                    }
                }
            }

This code fragment shows a client  that trys to connect the server... The sample of SDK(BluetoothChat) used same code except 
for (int i = 0; i < Connection.MAX_SUPPORTED && myBSock == null; i++) {
                for (int j = 0; j < 3 && myBSock == null; j++) { ....
I don't understand why?   what'more, it can't connect to multiple devices at the same time!
Thanks!!!

















2010/12/21 Morrison Chang <morriso...@gmail.com>

Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time Kristopher Micinski 12/22/10 6:57 PM
Many people have this problem, this implements a Bluetooth Piconet,
this is why this is using seven different UUIDs for the Bluetooth
socket.
I went through this example and saw how it is implemented, it is
similar to how we implement this client/server functionality in a few
of our applications in our research.
I believe the key to getting this to work is inthe mUuid list.

Take a close look at what this is doing?

            for (int i = 0; i < Connection.MAX_SUPPORTED && myBSock ==
null; i++) {
                for (int j = 0; j < 3 && myBSock == null; j++) {
                    myBSock = getConnectedSocket(myBtServer, mUuid.get(i));
                    if (myBSock == null) {
                        try {
                            Thread.sleep(200);
                        } catch (InterruptedException e) {
                            Log.e(TAG, "InterruptedException in connect", e);
                        }
                    }
                }
            }

What this code does is looks to connect to the device, but how does it
do so? It tries the socket multiple times, using multiple UUIDs for
the session. In essence it means that we can use UUID only *once*. So
instead this application implements using seven UUIDs, then the server
listens and accepts each UUID on the server side, this is what is done
with the following code:

                for (int i = 0; i < Connection.MAX_SUPPORTED &&
maxConnections > 0; i++) {
                    BluetoothServerSocket myServerSocket = mBtAdapter

.listenUsingRfcommWithServiceRecord(srcApp, mUuid.get(i));
                    BluetoothSocket myBSock = myServerSocket.accept();
                    myServerSocket.close(); // Close the socket now that the
                    // connection has been made.

                    String address = myBSock.getRemoteDevice().getAddress();

                    mBtSockets.put(address, myBSock);
                    mBtDeviceAddresses.add(address);
                    Thread mBtStreamWatcherThread = new Thread(new
BtStreamWatcher(address));
                    mBtStreamWatcherThread.start();
                    mBtStreamWatcherThreads.put(address,
mBtStreamWatcherThread);
                    maxConnections = maxConnections - 1;
                    if (mCallback != null) {
                        mCallback.incomingConnection(address);
                    }
                }

Now, on the client side of things what is done? The client does not
know how many active connections the server currently has. If we have
some agreed upon order that the clients must use we can simply use
this, however, in our case, we simply just try *each UUID* in sequence
until we "find the right one."

Hopefully this helps you, and everyone else who has questions about
this problem, feel free to email me with problems you have.

Short version:
  -- Use multiple UUIDs, you can only use one at once. So define seven
(max for piconet usage) and try each one until you find the right one.

Thanks,
Kristopher Micinski
Michigan State University

2010/12/22 苗鹏 <mp87...@gmail.com>

Re: Android bluetooth api connect to multiple devices at the same time koladoo nitish 5/17/12 5:36 AM
i have tried this solution.. but it does not work. it crashes on the third device connction. We get an error like this
"
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793): IOException in getConnectedSocket
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793): java.io.IOException: Service discovery failed
Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time Ali Rezaeian 5/19/12 1:03 PM
I am using the Android Bluetooth Chat Sample, and I was wondering how and where I should add codes to able to connect to multiple devices?
Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time Kristopher Micinski 5/21/12 8:37 AM
That seems to be a general problem, and it's typically with device
hardware, rather than anything you're doing.

Basically, may manufacturers cheap out on the BT adapters, (or the
lower level APIs aren't working properly).  It sucks, but it's nothing
you're doing, if I'm understanding your description correctly.

kris