I\'m trying to create a basic bluetooth application, for testing the device.
I got the code from developer.android. Here is the link : http://developer.android.com/
I worked through a similar learning process. I have tried to document what I learned in a series of examples.
This one might be of help:
http://digitalhacksblog.blogspot.com/2012/05/android-example-bluetooth-simple-spp.html
It is for setting up a simple connection between an Android device and a PC via bluetooth. The examples contain the Android files as well as an SPP server in java and one in perl for the PC.
Hope this helps.
Its working for me
BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class});
socket = (BluetoothSocket) m.invoke(device, 1);
bluetoothAdapter.cancelDiscovery();
socket.connect();
You'll have to provide a valid UUID for the service discovery.
BluetoothSocket sock = bdevice.createRfcommSocketToServiceRecord(VALID_UUID);
There are several common UUIDs for various standard (default) bluetooth services (Handsfree, File transfer, etc).
See here
Try using the Bluetooth Chat sample project provided as a part of the SDK if you are just trying to test the device. That code you're trying to use and the one provided on developer.android.com are included in the Bluetooth Chat example.
I don't know and I still don't understand the UUID stuff but the problem was the UUID. I'm using the UUID which I got from the kernel logs and it is 00001105-0000-1000-8000-00805F9B34FB
.
Make sure that your app is not trying to connect while the adapter is busy with discovery: It appears the problem was that before I called
clientSocket.connect()
I needed to call
btAdapter.cancelDiscovery()
This helped solve the same problem for me Matts Reco