Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I implemented that with sucess after a relevant amount of work, during the path i faced some tricky bugs, for instance I had to implement a Handshake protocol(something like <a href="http://en.wikipedia.org/wiki/Handshaking" rel="nofollow">that</a>) to avoid timeout problem during a connection attempt.</p> <p>Well, I started looking at the BluetoothChat example(Android SDK Sample), that implements communication between 2 devices. So, I modified that, to permit multiple connections. As the code became large, i will just tell you the approach I have used.</p> <p>Basically, all devices running my app can be a server or client. So each one, has always a BluetoothServerSocket(AcceptThread) running, so in this way, each device is always able to receive a request connection.</p> <p>A device that wants to connect, starts a ConnectThread, this thread it is started after a discovery process or if it choose BluetoothDevice of PairedDevices <a href="http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#getBondedDevices%28%29" rel="nofollow">Using getBondedDevices</a>.</p> <p>When a connection is established, I create a new Thread(ConnectedThread) that represents that connection. If you want to has different behavior that depends of you device role(master or slave) you can have a ConnectedThread subclass like MasterThread and SlaveThread</p> <p>The Android Documentation has a good explanation of how to work with Bluetooth at: <a href="http://developer.android.com/guide/topics/connectivity/bluetooth.html" rel="nofollow">http://developer.android.com/guide/topics/connectivity/bluetooth.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload