Java.io.IOException: [JSR82] when connected to a Bluetooth device

I am new to Android development. I want to send data via Bluetooth, but the following exception will come.

Connecting To Bluetooth Failed.
java.io.IOException: [JSR82] connect: Connection is not created (failed or aborted).
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:397)
odacPkg.odac.BluetoothCommunication.run(CommunicationActivity.java:493)

Below is my source code.

        final UUID applicationUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
        btDevice=bluetoothAdapterObj.getRemoteDevice(deviceMAC.toUpperCase());
        try {               
            BluetoothSocket btSocket = btDevice.createRfcommSocketToServiceRecord(applicationUUID);
            btSocket.connect();
            OutputStream outStream = btSocket.getOutputStream();
            outStream.write(sendData);
            btSocket.wait(CommunicationActivity.PACK_TIMEOUT);
            InputStream inStream = btSocket.getInputStream();
            inStream.read(receiveData);
            outStream.flush();
            outStream.close();
            outStream.close();
        }   
        catch (Exception e) {

        }
0
source share
1 answer

This is not a problem arising from your code, I decided to just restart Android devices. I think this is something strange in the operating system of Android devices, at least for version 4.1 jelly bean.

-2
source

All Articles