安卓蓝牙.connect()异常 Nexus 7 OBDII适配器

5

我正在使用连接设备的标准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;
        }

1
当我连接我的BT- dongle(串行UUID)时,在我的PC上(Nexus 4,Android 4.2,针对4.2的应用程序),我遇到了相同的错误。使用相同的连接方式编写的一年前的某个旧应用程序没有出现这些问题,但其针对的API为8。 - Martze
1
这篇文章讲述了关于4.2的一些问题。 - Martze
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接