开发者

Android Bluetooth Cross Platform Interoperability

I have a Bluetooth service that I programmed for .Net on a Windows machine and I would like my Android 2.1 phone to connect to it. The server is listening for the same UUID which the Androi开发者_C百科d is using to connect. But the connection is failing.

When I try to connect to devices that are not listening for that UUID, I get an exception with the message "Service discovery failed", but when I try to connect to the server that is listening for the right UUID a message box pops up saying:

"There was a problem pairing with bluetooth device."

And I get an exception with the message "Connection timed out." So it looks like the server and the Android are communicating, but there is some sort of failure during handshaking. I know that the Android requires that the server is paired with the phone and also encrypts the communication channel. Does anyone know which specifications are used to do this? I would love to get my server to respond properly to the connection attempt.

Thanks!


I figured out what was going wrong. The problem is that you have to pair the remote device with the Android before you try to make the connection because the pairing dialog does not always work. I am not sure if the bug is on the Android side or on the other device's side, but I was never shown the dialog that asks for the authentication code or that displays the authentication code on either device. So it looks like there are some compatibility issues out there. But if you explictly pair the devices beforehand, then the connection works.


You're right. I'm having the same issue here while trying to connect to an RS232 device with BluetoothChat sample program.

1- If not bonded, I get two errors in a row :

03-03 13:38:20.020: ERROR/BluetoothService.cpp(2077): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) // Probably because we're calling cancelDiscovery() as a "security" (it's already been cancelled at some point beforehand)
03-03 13:38:20.040: ERROR/BluetoothEventLoop.cpp(2077): onCreateDeviceResult: D-Bus error: org.bluez.Error.AlreadyExists (Device already exists) // This I don't understand

2- Once bonded through Bluetooth Settings, no problem. The connection is made perfectly and the program works.

I tried to check out the Android Source by myself but, given that I'm a newbie, it's kind of tough. If some experienced guy could work it out, it'd be great.


To answer Tomas - The SPP (Serial Port Profile) profile is broken on several HTC Android models, even 2.1 versions, but it is not consistent among the models.

HTC Desire - Does not work.
HTC Legend - Bad, but works for a while? HTC Hero with custom ROMs - Some work well, some not at all and some badly when doing sound at the same time.


All the previous answers are on the mark; essentially, pairing is required before connect.

However, I was getting the error even after pairing. (I had first tried to connect without pairing).

The workaround was to reboot the phone once. And now it is able to connect to the paired device fine. Sounds simple, but I spent quite some time debugging it. Hopefully useful to someone out there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜