Just to make it short. I want to connect to three devices and read the data from all the three at the same time. I know how to connect to one and i can read the data from that But What i want is to connect the other two and read from them.Any suggestions , or other example i can follow.
Here is part of the code which is similar to mine but shorter . This code can connect to one device using the mac. So How to modify this to connect to three devices at the same time and display the data they are sending?
Please help i really need it cause am stuck at this part of my project. Thanks for the help.
private boolean connected = false;
private BluetoothSocket sock;
private InputStream in;
public void test() throws Exception {
if (connected) {
return;
}
BluetoothDevice zee = BluetoothAdapter.getDefaultAdapter().
getRemoteDevice("00:14:C5:A1:02:67");
Method m = zee.getClass().getMethod("createRfcommSocket",
new Class[] { int.class });
sock = (BluetoothSocket)m.invoke(zee, Integer.valueOf(1));
devicecon.setText("Connecting......");
sock.connect();
devicecon.setText("Connected");
in = sock.getInputStream();
byte[] buffer = new byte[50];
int read = 0;
Log.d("ZeeTest", "++++ Listening...");
try {
while (true) {
read = in.read(buffer);
connected = true;
StringBuilder buf = new StringBuilder();
for (int i = 0; i < read; i++) {
int b = buffer[i] & 0xff;
if (b < 0x10) {
buf.append("0");
}
buf.append(Integer.toHexString(b)).append(" ");
}
Log.d("ZeeTest", "++++ Read "+ read +" bytes: "+ buf.toString());
}
} catch (IOException e) {}
Log.d("ZeeTest", "++++ Done: test()");