sockets - 蓝牙 Secureaccept() 失败、Nexus 7、Android 4.2.2

标签 sockets bluetooth android-4.2-jelly-bean nexus-7

我正在运行 Android SDK 4.2 示例包中的蓝牙聊天示例,未对代码进行任何修改。我的目标是运行 Android 4.2.2 的 Nexus 7。当我尝试安全连接到配对设备时,我立即收到这些错误。 Connect Insecure 也会失败,导致类似的错误。有时,我重新启动BT后,连接就会成功。

我对此进行了研究,并看到了许多关于 Android 4 上 BT 问题的引用,但我认为它们应该在后续的 4.2 版本中得到修复。 Nexus 7 是我唯一的设备,所以我想知道其他设备上是否也会出现这种情况。

这个问题有解决办法吗?预先感谢您的任何指导!

更新:经过进一步调查,我发现 this link ,这表明BT资源堆栈存在泄漏,在4.2.2中仍然存在,可以通过手动停止/重新启动BT来解决。有人找到了程序化的解决方法吗?

04-16 08:50:48.505: E/BluetoothChat(28905): +++ ON CREATE +++
04-16 08:50:48.535: E/BluetoothChat(28905): ++ ON START ++
04-16 08:50:48.535: D/BluetoothChat(28905): setupChat()
04-16 08:50:48.535: E/BluetoothChat(28905): + ON RESUME +
04-16 08:50:48.535: D/BluetoothChatService(28905): start
04-16 08:50:48.535: D/BluetoothChatService(28905): setState() 0 -> 1
04-16 08:50:48.545: W/BluetoothAdapter(28905): getBluetoothService() called with no BluetoothManagerCallback
04-16 08:50:48.545: D/BluetoothChatService(28905): Socket Type: SecureBEGIN mAcceptThreadThread[Thread-9834,5,main]
04-16 08:50:48.545: W/BluetoothAdapter(28905): getBluetoothService() called with no BluetoothManagerCallback
04-16 08:50:48.545: D/BluetoothChatService(28905): Socket Type: InsecureBEGIN mAcceptThreadThread[Thread-9835,5,main]
04-16 08:50:48.555: I/BluetoothChat(28905): MESSAGE_STATE_CHANGE: 1
04-16 08:50:48.615: D/libEGL(28905): loaded /system/lib/egl/libEGL_tegra.so
04-16 08:50:48.635: D/libEGL(28905): loaded /system/lib/egl/libGLESv1_CM_tegra.so
04-16 08:50:48.645: D/libEGL(28905): loaded /system/lib/egl/libGLESv2_tegra.so
04-16 08:50:48.675: D/OpenGLRenderer(28905): Enabling debug mode 0
04-16 08:52:08.625: E/BluetoothChat(28905): - ON PAUSE -
04-16 08:52:08.755: D/dalvikvm(28905): GC_CONCURRENT freed 134K, 4% free 7529K/7792K, paused 3ms+3ms, total 29ms
04-16 08:52:10.115: D/BluetoothChat(28905): onActivityResult -1
04-16 08:52:10.115: D/BluetoothChatService(28905): connect to: C8:D1:5E:2F:12:E8
04-16 08:52:10.115: D/BluetoothChatService(28905): setState() 1 -> 2
04-16 08:52:10.115: I/BluetoothChatService(28905): BEGIN mConnectThread SocketType:Secure
04-16 08:52:10.115: E/BluetoothChat(28905): + ON RESUME +
04-16 08:52:10.125: W/BluetoothAdapter(28905): getBluetoothService() called with no BluetoothManagerCallback
04-16 08:52:10.125: D/BluetoothSocket(28905): connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[54]}
04-16 08:52:10.135: I/BluetoothChat(28905): MESSAGE_STATE_CHANGE: 2
04-16 08:52:11.645: D/BluetoothChatService(28905): connected, Socket Type:Secure
04-16 08:52:11.645: D/BluetoothChatService(28905): Socket TypeSecurecancel Thread[AcceptThreadSecure,5,main]
04-16 08:52:11.645: D/BluetoothChatService(28905): Socket TypeInsecurecancel Thread[AcceptThreadInsecure,5,main]
04-16 08:52:11.645: D/BluetoothChatService(28905): create ConnectedThread: Secure
04-16 08:52:11.655: E/BluetoothChatService(28905): Socket Type: Insecureaccept() failed
04-16 08:52:11.655: E/BluetoothChatService(28905): java.io.IOException: read failed, socket might closed or timeout, read ret: -1
04-16 08:52:11.655: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:492)
04-16 08:52:11.655: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:469)
04-16 08:52:11.655: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothSocket.accept(BluetoothSocket.java:393)
04-16 08:52:11.655: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:131)
04-16 08:52:11.655: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:117)
04-16 08:52:11.655: E/BluetoothChatService(28905):  at com.example.android.BluetoothChat.BluetoothChatService$AcceptThread.run(BluetoothChatService.java:301)
04-16 08:52:11.655: D/BluetoothChatService(28905): setState() 2 -> 3
04-16 08:52:11.655: I/BluetoothChatService(28905): END mAcceptThread, socket Type: Insecure
04-16 08:52:11.655: E/BluetoothChatService(28905): Socket Type: Secureaccept() failed
04-16 08:52:11.655: E/BluetoothChatService(28905): java.io.IOException: read failed, socket might closed or timeout, read ret: -1
04-16 08:52:11.655: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:492)
04-16 08:52:11.655: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:469)
04-16 08:52:11.655: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothSocket.accept(BluetoothSocket.java:393)
04-16 08:52:11.655: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:131)
04-16 08:52:11.655: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothServerSocket.accept(BluetoothServerSocket.java:117)
04-16 08:52:11.655: E/BluetoothChatService(28905):  at com.example.android.BluetoothChat.BluetoothChatService$AcceptThread.run(BluetoothChatService.java:301)
04-16 08:52:11.655: I/BluetoothChatService(28905): END mAcceptThread, socket Type: Secure
04-16 08:52:11.655: I/BluetoothChatService(28905): BEGIN mConnectedThread
04-16 08:52:11.665: I/BluetoothChat(28905): MESSAGE_STATE_CHANGE: 3
04-16 08:52:36.985: E/BluetoothChat(28905): - ON PAUSE -
04-16 08:52:37.005: E/BluetoothChat(28905): -- ON STOP --
04-16 08:52:37.015: D/BluetoothChatService(28905): stop
04-16 08:52:37.015: E/BluetoothChatService(28905): disconnected
04-16 08:52:37.015: E/BluetoothChatService(28905): java.io.IOException: bt socket closed, read return: -1
04-16 08:52:37.015: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:416)
04-16 08:52:37.015: E/BluetoothChatService(28905):  at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
04-16 08:52:37.015: E/BluetoothChatService(28905):  at java.io.InputStream.read(InputStream.java:163)
04-16 08:52:37.015: E/BluetoothChatService(28905):  at com.example.android.BluetoothChat.BluetoothChatService$ConnectedThread.run(BluetoothChatService.java:454)
04-16 08:52:37.015: D/BluetoothChatService(28905): setState() 3 -> 0
04-16 08:52:37.015: E/BluetoothChat(28905): --- ON DESTROY ---
04-16 08:52:37.015: D/BluetoothChatService(28905): start
04-16 08:52:37.015: D/BluetoothChatService(28905): setState() 0 -> 1
04-16 08:52:37.025: W/BluetoothAdapter(28905): getBluetoothService() called with no BluetoothManagerCallback
04-16 08:52:37.045: D/BluetoothChatService(28905): Socket Type: SecureBEGIN mAcceptThreadThread[Thread-9842,5,main]
04-16 08:52:37.115: W/BluetoothAdapter(28905): getBluetoothService() called with no BluetoothManagerCallback
04-16 08:52:37.125: E/BluetoothChat(28905): +++ ON CREATE +++
04-16 08:52:37.125: D/BluetoothChatService(28905): start
04-16 08:52:37.125: D/BluetoothChatService(28905): setState() 1 -> 1
04-16 08:52:37.125: D/BluetoothChatService(28905): Socket Type: InsecureBEGIN mAcceptThreadThread[Thread-9843,5,main]
04-16 08:52:37.155: E/BluetoothChat(28905): ++ ON START ++
04-16 08:52:37.155: D/BluetoothChat(28905): setupChat()
04-16 08:52:37.155: E/BluetoothChat(28905): + ON RESUME +
04-16 08:52:37.155: D/BluetoothChatService(28905): start
04-16 08:52:37.155: D/BluetoothChatService(28905): setState() 0 -> 1
04-16 08:52:37.165: W/BluetoothAdapter(28905): getBluetoothService() called with no BluetoothManagerCallback
04-16 08:52:37.165: W/BluetoothAdapter(28905): getBluetoothService() called with no BluetoothManagerCallback
04-16 08:52:37.165: D/BluetoothChatService(28905): Socket Type: SecureBEGIN mAcceptThreadThread[Thread-9844,5,main]
04-16 08:52:37.175: D/BluetoothChatService(28905): Socket Type: InsecureBEGIN mAcceptThreadThread[Thread-9845,5,main]
04-16 08:52:37.215: I/BluetoothChat(28905): MESSAGE_STATE_CHANGE: 0
04-16 08:52:37.215: I/BluetoothChat(28905): MESSAGE_STATE_CHANGE: 1
04-16 08:52:37.225: I/BluetoothChat(28905): MESSAGE_STATE_CHANGE: 1
04-16 08:52:37.225: I/BluetoothChat(28905): MESSAGE_STATE_CHANGE: 1

最佳答案

看看我的问题。 android bluetooth can't connect

看起来这是 Android 本身的问题,而不是您的代码的问题。

关于sockets - 蓝牙 Secureaccept() 失败、Nexus 7、Android 4.2.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16038372/

相关文章:

mysql - 通过 localhost 连接 MySQL 不工作但 127.0.0.1 工作

ios - 您是否可以在不请求设备和广播用户许可的情况下向附近的设备广播数据?

linux - 如何在Windows上调试蓝牙堆栈,使用什么工具

android - 在 Jellybean 中,相机 Intent 在使用 FileProvider 时返回 RESULT.CANCELLED

android - 无法在 SearchView 中自动显示键盘

android - Jelly Bean webview 滚动不流畅

sockets - Windows服务中的Indy UDP Server无法监听

c - 如何在多线程程序中防止SIGPIPE?

php - 线程对象更改套接字资源 ID

android - 为什么 BLE 服务 UUid 在 android 和 iphone 中不同?