11
votes

I'm trying to use my Android phone as a handsfree kit (like the one for cars) in order to connect to another phone (any phone) and perform some handsfree functionality like (answer an incoming call, reject,.. etc) which can be done using the AT commands for handsfree profile. For that, I'm using the well-known Bluetooth chat App, and reflection work around in order to establish a connection with any device:

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

However, in order to achieve the handsfree functionality and understand the AT commands that I'm sending, the connected phone needs to be over the handsfree profile which uses the UUID: "0000111f-0000-1000-8000-00805F9B34FB"

Therefore, is there a way to achieve a connection to the handsfree profile?

Thanks!

1
I was able to establish the HF Bluetooth connection using Bluecove Library "bluecove.org" and now I can control and manage the calls on the connected phone using AT Commands. Also, for a complete Hands-free functionality, the connected phone routes the voice to Android but it doesn't receive it since it doesn't have the Sink role. I know that SCO channel is implemented in Android but as a source role (for sending the voice out to the headset only). Therefore, is there any way to implement the sink role in Android, does Android's BlueZ stack support that?mjabdelhadi
This is exactly what I'm trying to do. Have you been successful on that?Majid Yaghouti

1 Answers

3
votes

You should only use this code when you have no other choice. The 1 in this code is the RFCOMM port. Each service has it's own RFCOMM port. This port is usually random between 1 and 31. You need to know which port the service (here handsfree profile) is using on the device that you want to connect to. You have to use the createRfcommSocketToServiceRecord method from the BluetoothDevice object to do this:

try {   clientSocket = bluetoothDevice.createRfcommSocketToServiceRecord( serviceUUID ); }
catch (IOException e) 
{
  // handle error
} 

This code is the correct way to use Bluetooth and should replace the one you're using.