Android connect to Blackberry 655+ bluetooth headset

853 views Asked by At

I'm trying to write a test app which connects to BlackBerry 655+ bluetooth headset. Basically what i want to do in this app is connect to the headset and catch button pressures on it. I think that could be done by reading the socket's inputstream. Anyway, i get some errors right when i try to connect to the socket. Here's the code:

BluetoothSocket tmp = null;
try {
    tmp = mDevice.createRfcommSocketToServiceRecord(
                   UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
} catch(IOException e) {}
mSocket = tmp;

mBtAdapter.cancelDiscovery();

try {
    mSocket.connect();   // THIS ONE GIVES A "Service discovery failed" exception
} catch (IOException e1) {
Method m = null;
try {
    m = mDevice.getClass().getMethod(
          "createRfcommSocket", new Class[] {int.class});
} catch (SecurityException e) {
    e.printStackTrace();
} catch (NoSuchMethodException e) {
    e.printStackTrace();
}
try {
    tmp = (BluetoothSocket) m.invoke(mDevice, 1);
} catch (IllegalArgumentException e) {
            e.printStackTrace();
} catch (IllegalAccessException e) {
            e.printStackTrace();
} catch (InvocationTargetException e) {
            e.printStackTrace();
}
mSocket = tmp;

try {
    mSocket.connect();  // THIS ONE GIVES A "Connection refused" EXCEPTION
} catch (IOException e) {
    e.printStackTrace();
}
}

What am i doing wrong? I already tried different ports in the m.invoke(mDevice, X) instruction but it always gives "Connection refused"

2

There are 2 answers

3
user614538 On

I worked with Bluetooth before but with python and Java ME so I understand the basics. I don't know much about the android API though.

Where did you get the UUID code from? That could be one of the reasons for the Service discovery failed.

Each bluetooth device may have several services each of them associated to one port (or channel). If you are running ubuntu try using the hci tools to know to which channel connect or which service to search for.

1
garzanti On

Here you have an official list with UUIDs from Bluetooth SIG. For Headset Profile the UUID is 0x1108, the UUID used by you it is Base Universally Unique Identifier and it is used for SDP.