2

enter image description herei 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

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
lemuriyan
  • 606
  • 2
  • 7
  • 19

1 Answers1

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