3

I am mystified by two approaches to making BT connections in Android.

This is what I have done for as long as I can remember, and it has worked from 2.3+ devices to early 4.x. This what the Android docs describe as well.

private static final UUID sppUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(sppUUID);
bluetoothSocket.connect();

This has ceased to work on some newer Androids (Nexus 7 running 4.4), Cyanogenmod with this result (or similar):

java.io.IOException: read failed, socket might closed or timeout, read ret: -1

After much thrashing around--much of it in SO!--I find this works

Method m = bluetoothDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
bluetoothSocket = (BluetoothSocket) m.invoke(bluetoothDevice, 1);
bluetoothSocket.connect();

Where does this come from? Why does this work over the other approach?

Thank you

PVS
  • 1,168
  • 11
  • 24
  • do you want communication in text or sending file connections..?? there should be same UUID. Check this [BluetoothChatApp](https://android.googlesource.com/platform/development/+/25b6aed7b2e01ce7bdc0dfa1a79eaf009ad178fe/samples/BluetoothChat/src/com/example/android/BluetoothChat/BluetoothChatService.java) – SilentKiller Jan 21 '14 at 05:08

0 Answers0