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

2023-09-07 02:14:40 作者:【與世隔絕】

我是新android开发。我想使用蓝牙发送数据,但以下情况除外来了。

 连接到蓝牙失败。java.io.IOException异常:[JSR82]连接:连接还没有建立(或失败中止)。在android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:397)odacPkg.odac.BluetoothCommunication.run(CommunicationActivity.java:493) 

以下是我的源$ C ​​$ C。

 最后UUID applicationUUID = UUID.fromString(00001101-0000-1000-8000-00805F9B34FB);        btDevice = bluetoothAdapterObj.getRemoteDevice(deviceMAC.toUpperCase());        尝试{            的BluetoothSocket btSocket = btDevice.createRfcommSocketToServiceRecord(applicationUUID);            btSocket.connect();            的OutputStream outStream = btSocket.getOutputStream();            outStream.write(送出数据);            btSocket.wait(CommunicationActivity.PACK_TIMEOUT);            的InputStream inStream中= btSocket.getInputStream();            inStream.read(receiveData的);            outStream.flush();            outStream.close();            outStream.close();        }        赶上(例外五){        } 

解决方案

这不是从你的code来一个问题,我解决它只是重新启动Android设备。我猜疗法采用的是Android设备,至少在4.1版本果冻豆的执行系统,一些奇怪的事情。

轻松应对双11,百万级物理和虚拟网络设备的网络智能化实践

I am new to android development. I want to send data using Bluetooth but the following exception coming.

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)

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

        }

解决方案

It's not an issue coming from your code, I solved it simply rebooting android devices. I guess ther is something strange in the operative system of android devices , at least for version 4.1 jelly bean.