I am getting a issue to send Commands from my android device to Bluetooth device.
Bluetooth is associated with a micro-controller. My effort is below:
I have a very simmilar code and it's working, maybe one of the main differences it that I'm doing a reset of threads:
// Reset the ConnectThread because we're done
synchronized (blablabla.this) {
mConnectThread = null;
}
// Cancel the thread that completed the connection
if (mConnectThread != null) {
mConnectThread.cancel();
mConnectThread = null;
}
// Cancel any thread currently running a connection
if (mConnectedThread != null) {
mConnectedThread.cancel();
mConnectedThread = null;
}
// Start the thread to manage the connection and perform transmissions
mConnectedThread = new ConnectedThread(socket);
mConnectedThread.start();
Just after you do:
mmSocket.connect();
hope it helps.
I tried this library. You can try it also https://github.com/palaima/AndroidSmoothBluetooth
As you have mentioned that the issue is there on mmSocket.connect(); line hence, the problem is not while you are sending the command but creating a connection i.e. you are not able to retrieve a BluetoothSocket in opened or connected state.
What should you do ?
Try to use the below code with UUID , its valid for my bluetooth dongles.
UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
createInsecureRfcommSocketToServiceRecord(MY_UUID)
Let me know if this works for you.
Also check, https://stackoverflow.com/a/18786701/1503130