【发布时间】:2014-03-28 03:16:53
【问题描述】:
不幸的是,我在使用 android 的蓝牙时遇到了一些问题。对于我的测试环境,我使用带有 Android 4.4.2 的 Nexus 4。
我的 PC 上有一个 Java 应用程序,它使用 bluecove 作为客户端建立 SPP 连接。该程序正在寻找一个特殊的服务名称并与我的安卓手机连接。之后它会向我的安卓手机发送 72 个字节并等待回复。当得到那个答案时,程序会休眠 3 秒,然后重新启动。
在我的安卓手机上,我有一个带有后台蓝牙监听器的应用程序,它在启动时启动。此应用程序基于 BluetoothChat 示例演示。接收蓝牙数据时,我会检查传入数据并发送回答案。
一切正常。但是在 489 个蓝牙连接之后,android 应用程序失败,并在 PC-java-app 运行时出现以下错误 sn-p:
getBluetoothService() called with no BluetoothManagerCallback
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x41b34ba8)
FATAL EXCEPTION: main
Process: de.tum.lme.diamantum:remote_blue, PID: 21567
java.lang.NullPointerException: FileDescriptor must not be null
at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:174)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:905)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:897)
at android.bluetooth.IBluetooth$Stub$Proxy.createSocketChannel(IBluetooth.java:1355)
at android.bluetooth.BluetoothSocket.bindListen(BluetoothSocket.java:349)
at android.bluetooth.BluetoothAdapter.createNewRfcommSocketAndRecord(BluetoothAdapter.java:1055)
at android.bluetooth.BluetoothAdapter.listenUsingRfcommWithServiceRecord(BluetoothAdapter.java:976)
at com.test.btconn.BluetoothHandling$AcceptThread.<init>(BluetoothHandling.java:449)
at com.test.btconn.BluetoothHandling.start(BluetoothHandling.java:216)
at com.test.btconn.BluetoothListenerService.setupBtSockets(BluetoothListenerService.java:330)
at com.test.btconn.BluetoothListenerService.manageBtState(BluetoothListenerService.java:249)
at com.test.btconn.BluetoothListenerService.setBtStateDisconnected(BluetoothListenerService.java:383)
at com.test.btconn.BluetoothListenerService.access$5(BluetoothListenerService.java:378)
at com.test.btconn.BluetoothListenerService$2.handleMessage(BluetoothListenerService.java:421)
所以应用程序的 ParcelFileDescriptor 有问题,它突然为空。但是为什么呢?
上述所有情况也会在 PC-java-app 上更改暂停时间时发生,使用各种数据大小来传输和使用不同的智能手机。当使用反射“listenUsingRfcommWithServiceRecord”时,同样会在 505 次传输之后发生。也使用唤醒锁没有任何改变。
顺便说一句,我在使用 BluetoothChat 示例时得到了相同的行为。
那么,有没有人暗示,会发生什么?
更新:
BluetoothServerSocket 在每次连接后关闭,如果蓝牙状态为 3,则关闭 BluetoothSocket。
【问题讨论】:
-
我想知道您的旧套接字是否没有关闭,因此您最终超出了某些系统或进程限制并且无法创建新的。
-
知道失败的原因吗?
-
想知道 4.4.3 是否解决了这个问题。有大量与 BT 相关的修复
-
您的设备似乎超过了允许的最大 fd 数。在这里查看stackoverflow.com/questions/13262339/…。你确定你的应用关闭了所有资源吗?
标签: java android bluetooth spp