IOException: read failed, socket might closed - Bluetooth on Android 4.3

后端 未结 16 2288
天涯浪人
天涯浪人 2020-11-22 04:08

Currently I am trying to deal with a strange Exception when opening a BluetoothSocket on my Nexus 7 (2012), with Android 4.3 (Build JWR66Y, I guess the second 4.3 update). I

16条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 04:50

    I ran into this problem and fixed it by closing the input and output streams before closing the socket. Now I can disconnect and connect again with no issues.

    https://stackoverflow.com/a/3039807/5688612

    In Kotlin:

    fun disconnect() {
        bluetoothSocket.inputStream.close()
        bluetoothSocket.outputStream.close()
        bluetoothSocket.close()
    }
    

提交回复
热议问题