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

问题描述 投票:0回答:1

我正在使用标准 API 程序连接到设备。特别是 OBDII 蓝牙适配器。

我有两个不同型号的 OBDII 蓝牙适配器。运行完全相同的代码,第一个代码将与我测试过的每部手机/平板电脑配对和连接,不会出现问题。第二个可以正常配对和连接,除了我的 Nexus 7 运行 android 4.2

它抛出一个 IO 异常:

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;
        }
android bluetooth ioexception obd-ii
1个回答
0
投票

我知道这是一个老问题。但由于我无法在网上找到任何解决方案。搜索此内容的人可能对我发现的解决方法感兴趣:IOException:读取失败,套接字可能关闭 - Android 4.3 上的蓝牙

© www.soinside.com 2019 - 2024. All rights reserved.