最佳答案
我对这个“java.io.IOException: read failed, socket might closed or timeout, read ret: -1”的个人经验
以我为例。蓝牙设备已连接到另一台设备并测试了连接。后来,我断开了与另一台设备的连接并尝试连接到我的设备,但未建立连接。
多次打开和关闭设备后。我的设备已连接到蓝牙设备。
连设备都断开了。设备连接的地址未从设备中删除。我正在使用条形码扫描仪设备。
有这样的可能性。请通过关闭和打开蓝牙设备并重置蓝牙设备来检查一次。
这样试试
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) {
}
关于android - 牛轧糖套接字关闭时无法连接蓝牙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50875056/