I have written a normal code to connect to a standard bluetooth device ( a wocket). What I am doing is connecting to the wocket (which is just a piece of bluetooth chip), as a client. I am using a random UUID to connect to the wocket. But the connect method is throwing a IO Exception telling me that it is not able to connect to the Bluetooth device. The code that I am using is from Android Developers forum here : http://developer.android.com/guide/topics/connectivity/bluetooth.html
private class ConnectThread extends Thread { private final BluetoothSocket mmSocket; private final BluetoothDevice mmDevice;
public ConnectThread(BluetoothDevice device) {
// Use a temporary object that is later assigned to mmSocket,
// because mmSocket is final
BluetoothSocket tmp = null;
mmDevice = device;
// Get a BluetoothSocket to connect with the given BluetoothDevice
try {
// MY_UUID is the app's UUID string, also used by the server code
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) { }
mmSocket = tmp;
}
public void run() {
// Cancel discovery because it will slow down the connection
mBluetoothAdapter.cancelDiscovery();
try {
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
mmSocket.connect();
**This call is throwing and IOException saying:
java.io.IOException Discovery Failed.
**
} catch (IOException connectException) {
// Unable to connect; close the socket and get out
try {
mmSocket.close();
} catch (IOException closeException) { }
return;
}
// Do work to manage the connection (in a separate thread)
manageConnectedSocket(mmSocket);
}
/** Will cancel an in-progress connection, and close the socket */
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) { }
}
}
What could be the reason the wocket is throwing an IOException. I don't think it makes any sense to connect to it being a server as for a server you establish a UUID and then you expect the client to have the same UUID, which is not possible in my case because I cannot program the wocket.
I am using an HTC one x with Android 4.0 as the testing device.
Thank you in advance.