This tutorial is an improved version of the previous
Serial tutorial.
We will create a chat example between two Android devices.
Using BluetoothAdmin we search for in-range devices and then allow the user to connect to a device. If the device were not paired before then a dialog will show to confirm the pairing process.
The first activity includes two buttons:
"Search for devices" button will start a discovery process that takes about 12 seconds.
"Make device discoverable" button does two things. First it sends an Intent that makes the device discoverable for 300 seconds. It then calls Serial1.Listen to listen for incoming connections.
If the connection is established successfully then we start the second activity:
In the second activity we use AsyncStreams to send and receive messages.
As we use AsyncStreams in both sides of the connection we can easily use "prefix mode". In this mode we always receive complete messages.
The code is attached.