1

Can someone explain to me how Bluetooth actually works when connecting an Android device to another one.

Here is what I think I know.

I have two devices.

One will be a client and the other the server, depending which initiates the connection. The Android device will do a search for devices in Discoverable Mode. The Android device can list previously paired devices.

A BluetoothSocket is opened to create the connection between the devices. Data can now be transfered Socket can be closed when completed

Question : if a device shows that there is a connection with a LED, should that LED flicker once the BluetoothSocket.connect() is called.

Is there anywhere I can find literature on how it works ect..

The reason for this question is due to my earlier post :

Android Bluetooth Connecting Error

I'm not sure If i am actually connected or not. The Android documentation says there is a boolean called BluetoothSocket.isConnected() but I dont seem to be able to find it. so I cant figure out if I am actually connected or not, and I dont know after "being connected" if I can just start sending data.

Community
  • 1
  • 1
Robert de Klerk
  • 624
  • 3
  • 12
  • 24
  • Try http://www.bluetooth.com/Pages/Tech-Info.aspx ? – Marc B Oct 31 '11 at 20:46
  • Change is necessary for android 2.1 and 2.2 devices. Don't exactly know why but if you don't do it it simply doesn't work. –  Dec 11 '11 at 23:05

1 Answers1

0

The link for BluetoothSocket.isConnected() is here. The documentation says Since API level 14, which means you need to update your sdk to r14 in order to use the method.

EDIT: This link may help you to find out if you're connected to another bluetooth device

Community
  • 1
  • 1
Zerhinne
  • 1,987
  • 2
  • 22
  • 43
  • Ya the Dev pages say its there, but in eclipse it isnt. – Robert de Klerk Oct 31 '11 at 23:47
  • thanks man, figured it was something silly like that. Also I found out how to connect correctly, had to substitute a line of code. `tmp = device.createRfcommSocketToServiceRecord(MY_UUID);` with: `Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});` `tmp = (BluetoothSocket) m.invoke(device, 1);` – Robert de Klerk Nov 01 '11 at 00:27
  • Glad that my answer helped you! Happy coding! =) – Zerhinne Nov 01 '11 at 00:29
  • Not sure why that change worked, but it did. Any explanation will be great. – Robert de Klerk Nov 01 '11 at 00:33