The question you've referred to there is very useful as it provides a workaround for a situation where the usual call to .createRfcommSocketToServiceRecord()
fails to work. I have personally used that workaround solution in a project I'm doing right now. What I do is I attempt the .createRfcommSocketToServiceRecord()
call first, and if that fails, my code then attempts to connect with the .getClass().getMethod("createRfcommSocket", new Class[]{int.class});
workaround. Having experimented with a number of Bluetooth-to-serial PCBs, some of them tend to be a bit 'awkward' and the latter reflection method works when the .createRfcommSocketToServiceRecord()
does not.
However... although that question you referenced does provide a very useful compact piece of code, I don't think it's the best place for you to start. The place you should start is at Android's Bluetooth documentation, which explains the whole process extremely well, including how to use separate Threads
to handle discovery, connection, etc. In fact it's really easy to get started using the Bluetooth Chat source code. Using that, you can get up and running and connected to a Bluetooth-serial module very quickly. You just need to make sure you change the UUID to that required for Serial Port Profile (SPP):
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
That will hopefully be enough to have a simple application that will talk to your Bluetooth serial module. The Bluetooth Chat example application also provides you with dialogs that handle device discovery, pairing, and all that good stuff, so you don't have to mess about hard-coding in your device's MAC address like you have been.
If you have problems connecting then you need to be specific about what's actually happening; i.e., what exceptions you're getting, and so forth.