我正在使用连接设备的标准API程序,具体地说是OBDII蓝牙适配器。
我有两个不同型号的OBDII蓝牙适配器。使用完全相同的代码,第一个适配器可以在我测试的每个手机/平板电脑上无异常配对和连接。第二个适配器可以正常配对和连接,但在运行Android 4.2的Nexus 7上出现了IOexception:read failed, socket might closed or timeout, read ret: -1
。
我原以为这只是设备本身或更新版本的问题...但是另一款软件“torque”能够从我的Nexus 7连接到任何一个适配器。
因此,很明显我正在做某些错误/不同之处,而这只有在较新的操作系统中才会成为问题???
非常感谢您提供任何帮助来解决这个问题。
public void run() {
Log.i(TAG, "BEGIN mConnectThread");
setName("ConnectThread");
// Always cancel discovery because it will slow down a connection
mAdapter.cancelDiscovery();
// Make a connection to the BluetoothSocket
try {
// This is a blocking call and will only return on a
// successful connection or an exception
mmSocket.connect(); <=**This is where the exception is thrown
} catch (IOException e) {
Etype = "Connection to: " + mmDevice.getName() + " at: "
+ mmDevice.getAddress() + " failed: " + e.getMessage();
connectionFailed();
// Close the socket
try {
mmSocket.close();
} catch (IOException e2) {
Log.e(TAG, "unable to close() socket during connection failure", e2);
}
// Start the service over to restart listening mode
BluetoothChatService.this.start();
return;
}