在尝试连接Android中的蓝牙时接收abortNative

时间:2014-02-10 16:56:52

标签: java android sockets bluetooth

我在Android中遇到了一个奇怪的蓝牙应用问题。我正在尝试开发的应用程序是蓝牙ad-hoc网络。问题在于createInsecureRfcommSocket。我是我的应用程序,当用户单击发现按钮时,它会触发循环以尝试连接到链接列表中保存的所有已发现设备(我事先进行了发现)。然后,基于此过程的每个连接节点将接收发现请求并递归地执行相同的过程,尝试连接到它预先发现的所有节点,除了它收到请求的节点。我面临的问题是,很多时候,节点不会接受打开套接字,尽管他们已经在监听蓝牙服务器套接字并且日志看起来像:

02-09 17:36:21.898: I/BluetoothManetCommMgr(29670): Insitiating communication thread...
02-09 17:36:21.898: V/BluetoothSocket.cpp(29670): initSocketNative
02-09 17:36:21.898: V/BluetoothSocket.cpp(29670): ...fd 49 created (RFCOMM, lm = 0)
02-09 17:36:21.898: V/BluetoothSocket.cpp(29670): initSocketFromFdNative
02-09 17:36:22.078: D/BluetoothUtils(29670): isSocketAllowedBySecurityPolicy start : device null
02-09 17:36:34.085: V/BluetoothSocket.cpp(29670): abortNative
02-09 17:36:34.085: V/BluetoothSocket.cpp(29670): ...asocket_abort(49) complete
02-09 17:36:34.085: V/BluetoothSocket.cpp(29670): destroyNative
02-09 17:36:34.085: V/BluetoothSocket.cpp(29670): ...asocket_destroy(49) complete

注册服务器套接字的代码片段是基本的反映:

Method m = mBluetoothAdapter.getClass().getMethod("listenUsingInsecureRfcommOn", new Class[] { int.class });
tmp = (BluetoothServerSocket) m.invoke(mBluetoothAdapter, 1);

而在客户端,我使用以下代码进行连接:

Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);

然后我降低了我的要求,事先手动连接所有客户端。意思是,我会让每个Android手机事先执行发现,然后通过单击每个设备上的按钮将Android手机连接到另一个手机,直到我连接所有设备。我仍然经常看到问题发生的频率,特别是当手机刚刚与手机建立连接时,第二个对另一部手机的请求可能会失败并且上面的abortNative响应相同。顺便说一下,我使用了常规的createInsecureRfcommSocket而没有反射,但仍然会出现同样的问题。

知道问题可能是什么?

0 个答案:

没有答案