android蓝牙连接错误(读取失败的套接字可能已关闭或超时)
我想从android设备中的应用程序连接到远程设备(配对)。远程设备为模块HC-05。android蓝牙连接错误(读取失败的套接字可能已关闭或超时),android,bluetooth,arduino,Android,Bluetooth,Arduino,我想从android设备中的应用程序连接到远程设备(配对)。远程设备为模块HC-05。 我的代码是: UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standard SerialPortService ID try { mSocket = MyDevice.createRfcommSocketToServiceRecord(uuid); } catch (IOException e) {
我的代码是:
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standard SerialPortService ID
try {
mSocket = MyDevice.createRfcommSocketToServiceRecord(uuid);
} catch (IOException e) {
Toast.makeText(this, "S", Toast.LENGTH_SHORT).show();
}
ba.cancelDiscovery();
try {
mSocket.connect();
} catch (IOException e){
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
Log.e("YOUR_APP_LOG_TAG1", "I got an error", e);
}
try {
mOutputStream = mSocket.getOutputStream();
mInputStream = mSocket.getInputStream();
} catch (IOException e) {
Toast.makeText(this, "io", Toast.LENGTH_SHORT).show();
}
但是我在mSocket.connect()行中得到一个错误
错误:
读取失败的套接字可能已关闭或读取重试超时
请帮忙。这可能是由很多事情造成的——就我而言,我发现了三个原因:
你得到答案了吗?我也得到了同样的问题。请参考:-虽然这可能是原因,但这不是主要原因,请参考:-