java.io.IOException:[JSR82]连接到蓝牙设备

时间:2014-02-25 08:58:54

标签: android bluetooth

我是Android开发的新手。我想使用蓝牙发送数据,但会出现以下异常。

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)

以下是我的源代码。

        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) {

        }

1 个答案:

答案 0 :(得分:-2)

这不是来自您的代码的问题,我解决了它只是重启Android设备。我想在Android设备的操作系统中有一些奇怪的东西,至少对于4.1版的软糖豆来说。