示例代码的蓝牙连接问题
我正在尝试为游戏实现蓝牙多人游戏功能。但连接存在问题。这很令人困惑。我正在使用 Android 的示例代码,因为我以前从未尝试过这样的事情。
该示例是一个简单的BluetoothChat。刚才我尝试再次配对这些设备。
(至少 Android 2.1)
摩托罗拉 FlipOut 索尼爱立信 X10 迷你 HTC Legends
如果 FlipOut 正在扫描另一台设备并发送配对请求,则一切正常。如果另外两台设备尝试连接到 FlipOut,其中一台设备上会出现配对请求。点击配对后没有任何反应。几秒钟后,我收到一条 Toast 消息“无法连接到设备。
我对 TicTacToe 使用相同的代码。但行为发生了变化。FlipOut 作为主机没有任何问题。但 FlipOut 无法连接到其他设备最近几天我尝试了很多设备,例如三星 Galaxy S、索尼爱立信 X8、索尼爱立信 X10...
我找不到规律,我读到三星和 HTC 的“listenUsingRfcommWithServiceRecord”方法有问题。已于二月修复。
有人可以解释为什么它无法正常工作以及如何修复它吗?如果我进入设置并尝试建立连接,这意味着必须有解决方案。代码不能完美运行?
我不确定它是否有助于找到解决方案,但我安装了来自 Android Market 的具有蓝牙多人游戏功能的游戏“Galaxir”,但它也不能完美运行。
I am trying to implement a bluetooth multiplayer feature for a game. But there are problems with the connection. It is confusing. I am using the sample code of Android since I never tried something like this before.
The sample is a simple BluetoothChat. Just now I tried to pair these devices one more time.
(At least Android 2.1)
Motorola FlipOut
SonyEricsson X10 mini
HTC Legends
If the FlipOut is scanning for another device and sends a pairing request everything work fine. If the other two devices try to connect to the FlipOut a pairing request appear on one device. After clicking on pairing nothing happends. After a few seconds I got a Toast-message" unable to connect to device.
I use the same code for my TicTacToe. But the behavior changes. The FlipOut works as host without any problems. But the FlipOut can't connect to other devices. The last days I tried many devices. e.g. Samsung Galaxy S, Sony Ericsson X8, Sony Ericsson X10...
I can't find a regularity. I read Samsung and HTC had a problem with the method "listenUsingRfcommWithServiceRecord". But it should have been fixed February.
Can someone explain why it won't work properly and how I can fix it. If I go to settings and try to make a connection, everything works fine. That means there have to be solution, even though the sample code isn't working perfectly?
I am not sure wether it helps to find a solution. But I install the game "Galaxir", an app from the Android Market with Bluetooth multiplayer feature. And it doesn't work flawless as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用此代码进行套接字连接,而不是
createRfcommSocketToServiceRecord()
Try to use this code for Socket Connection instead of
createRfcommSocketToServiceRecord()
我运行的蓝牙示例也不起作用。这是因为他们没有在清单中声明该服务。
将您的清单替换为以下代码,它应该可以工作。
The bluetooth example I was running wasn't working either. It was because they didn't declare the service in the manifest.
Replace your manifest with the following code and it should work.