The question you were talking about is very useful as it provides a workaround for a situation where a regular call to .createRfcommSocketToServiceRecord() not working. I personally used this workaround in the project that I am currently doing. What I do, I first try to make a call to .createRfcommSocketToServiceRecord() , and if that fails, my code then tries to connect to the .getClass().getMethod("createRfcommSocket", new Class[]{int.class}); . After experimenting with multiple Bluetooth-to-serial .createRfcommSocketToServiceRecord() , some of them are generally a bit "awkward," and the last reflection method works when .createRfcommSocketToServiceRecord() does not.
However ... although this question you are referring to gives a very useful compact code, I don't think this is the best place for you. The place you should start is in the Bluetooth documentation for Android , which explains the whole process very well, including how to use separate Threads to handle discovery, connection, etc. It is actually very easy to start using the source code of the Bluetooth Chat . Using this, you can quickly get up and work and connect to the Bluetooth-serial module. You just need to make sure that you change the UUID to the value required for the serial port profile (SPP):
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
This, I hope, will be enough to have a simple application that will talk to your serial Bluetooth module. The Bluetooth Chat sample application also provides you with dialog boxes that handle device discovery, pairing, and all these good things, so you donβt have to worry about hard-coding the MAC address of your device like you do.
If you are having trouble connecting, you should be specific about what is actually happening; that is, what exceptions do you get, etc.
Trevor Feb 06 '12 at 18:22 2012-02-06 18:22
source share