Hi, I am trying to create an Android application that will connect to the Blue SMiRF Bluetooth dongle to which I want to send data. I read the developer pages and looked at several different examples, but I am currently having problems creating a socket connection. Part of the Bluetooth code pretty much refers to the example I could find. When I try to connect to a Bluetooth dongle, the application receives power because there is some error that I am not handling correctly. However, I also tried to use the application to connect to another PC, and for some reason the connection would not be established correctly, although I already connected to the device through the Bluetooth settings before I even started the application. I posted some of the most important codes below, where I thinkwhat my problem may be. Any help would be greatly appreciated, please let me know if I write any additional code.protected void connect(BluetoothDevice device) {
try {
socket = device.createRfcommSocketToServiceRecord(UUID.fromString("a60f35f0-b93a-11de-8a39-08002009c666"));
socket.connect();
Log.d("EF-BTBee", ">>Client connectted");
InputStream inputStream = socket.getInputStream();
OutputStream outputStream = socket.getOutputStream();
outputStream.write(new byte[] { (byte) 0xa0, 0, 7, 16, 0, 4, 0 });
new Thread() {
public void run() {
while(true)
{
try {
Log.d("EF-BTBee", ">>Send data thread!");
OutputStream outputStream = socket.getOutputStream();
outputStream.write(new byte[] { (byte) 0xa2, 0, 7, 16, 0, 4, 0 });
} catch (IOException e) {
Log.e("EF-BTBee", "", e);
}
}
};
}.start();
} catch (IOException e) {
Log.e("EF-BTBee", "", e);
} finally {
if (socket != null) {
try {
Log.d("EF-BTBee", ">>Client Close");
socket.close();
finish();
return ;
} catch (IOException e) {
Log.e("EF-BTBee", "", e);
}
}
}
}`
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
socket = (BluetoothSocket) m.invoke(device, 1);
"socket =" .