开发者

Android <-> bluetooth<->J2ME connectivity problems

I'm trying to get a Samsung Galaxy Ace with Androi开发者_运维技巧d to communicate with a Nokia N95 via Bluetooth. I have written an application for the J2ME side that communicates just fine using 2 symbian devices. I've also created a version for Android that communicates very well between Android devices. Initiating a connection from J2ME to Android works as well. Creating a connection from Android to J2ME gives me the problems.

Focusing on the problem: The first connection attempt fails using createRfcommSocketToServiceRecord. I then try the workaround using reflection and the createRfcommSocket method to channel 1, then 2, then 3, then 4, if they fail respectively. At one point I will have a connection and I can send data but when I try to receive using InputStream.read() it just hangs so I think the connection in J2ME is somehow not piped to my application.

So I created test applications to see what is wrong on the small scale. The N95 sets up a listener with a UUID encrypted and authenticated and the Android application creates a connection with createRfcommSocketToServiceRecord. This works! I can also run the real Android application and send messages to the test application of the N95. From this experience I have drawn the conclusion that the fault must lie in the J2ME version.

I am wondering if anyone has tips on how to go about debugging this. I am currently commenting out code, building, sending the app to the phone, installing, testing, repeating. This is very weary and is going very slow but I have no other option for testing this. I would also appreciate insight on why createRfcommSocket connection doesn't reply. Do I have to register something on the J2ME side? Thanks for your time.


I have resolved this particular issue by reviewing my code in detail and have found that I had incorrectly implemented my custom output streams.

out.write(x);
out.write(y);
out.flush();

the stream is not automatically flushed in j2me

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜