i have successfully import the google sample Bluetooth chat project and fix run time permission but unable to connect the device. socket closed i tried lot but unfortunately can't fix this please help to fix this issue
Asked
Active
Viewed 166 times
2

Phantômaxx
- 37,901
- 21
- 84
- 115

lemuriyan
- 606
- 2
- 7
- 19
-
what about some code? Log from Logcat? something... :) – Tomer Petel Jun 15 '18 at 11:58
-
Please check below code – lemuriyan Jun 15 '18 at 12:05
1 Answers
0
My personal experience with this “java.io.IOException: read failed, socket might closed or timeout, read ret: -1”
In my case. The blue-tooth device is connected to another device and tested the connection. Later, I disconnected the connection from another device and try to connect to my device but, connection is not established.
After turn-on & turn-off of device several time. my device is connected to blue-tooth device.
Even the device is disconnected. The address of the device connection were not removed from device. I was using barcode scanner device.
There is a possibility like this. Please check once by turning off and on and also reset the bluetooth device.
Try like this
try {
mmSocket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"));
mmSocket.connect();
} catch (IOException e) {
Log.d(TAG, "Fail Attempt1 : " + e.toString());
try{
mmSocket =(BluetoothSocket) mmDevice.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class}).invoke(mmDevice,1);
mmSocket.connect();
} catch (Exception e1){
try {
mmSocket.close();
} catch (IOException e5) {
}

Chethan Kumar
- 185
- 1
- 12
-
-
In my case. I'm experiencing the same situation now als. If i connect bluetooth device with another mobile. It wont connect to mine. I use to turn off & on the bluetooth device many time. at some instance it ll connect. – Chethan Kumar Jun 15 '18 at 12:29
-
-
your are expecting send & receive connection or only receive connection through bluetooth ? – Chethan Kumar Jun 15 '18 at 12:51
-
I would like to add one more changes. Call mChatService.connect(mDevice); at receiver "BluetoothDevice.BOND_BONDED". after pairing of device the connection will start to establish – Chethan Kumar Jun 15 '18 at 12:56
-