Good day, I am trying to create an Bluetooth application and I am failing to connect to another Android device. The problem which seems to be occurring is in the outgoing connection createRfcommSocketToServiceRecord(UUID)
- in which I believe the UUID
is not correct for both devices. The documentation says:
if you are connecting to an Android peer then please generate your own unique UUID.
My question is - if the other android device does not have my application installed, how do I connect to it with the proper UUID
? I have tried simply using the generic UUID
00001101-0000-1000-8000-00805F9B34FB
, but that does not seem to resolve the issue.
Here is a part of the code sample:
private static final UUID MY_UUID_SECURE =
UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private class ConnectThread extends Thread {
BluetoothDevice mdevice;
BluetoothSocket mclientSocket;
//private String mSocketType;
private Handler handler;
private ProgressDialog dialog;
public ConnectThread(BluetoothDevice device) {
mdevice = device;
BluetoothSocket temp = null;
try {
System.out.println("making connection to remote device");
temp = mdevice.createRfcommSocketToServiceRecord(MY_UUID_SECURE);
} catch (IOException e) {
e.printStackTrace();
}
Log.i(TAG, "Bluetooth Socket" + temp.toString() + "obtained");
mclientSocket = temp;
}
public synchronized void run() {
try {
Log.i(TAG, "starting to connect");
mclientSocket.connect();
} catch (IOException e) {
Log.e(TAG, "connection Failed");
try {
mclientSocket.close();
} catch (IOException e2) {
; // Do nothing.
}
}
}
//public void cancel() {
//try {
// mclientSocket.close();
//} catch (IOException e) {
//Log.e(TAG, "close() of connect " + mSocketType + " socket failed", e);
//}
//}
Note: I have not yet implemented the Bluetooth Server socket, but am instead trying to understand how you connect to another Android device that does not have my application installed. Help appreciated as always. Thank you.