Home » Android » bluetooth – How to send AT commands based on BT Hands-Free profile in android?

bluetooth – How to send AT commands based on BT Hands-Free profile in android?

Posted by: admin June 15, 2020 Leave a comment


I am trying to establish Bluetooth connection between an Android device with other mobile phone over Handsfree profile. I am using following code –

private static final UUID MY_UUID = UUID.fromString("0000111F-0000-1000-8000-00805F9B34FB"); // UUID for Hands free profile   

// Some code...

// Get Bluetooth Adapter.
m_oBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

// Some code...

// For paired BT device, getting a connection established.
if(null != m_oBluetoothDevice)
    if(BluetoothDevice.BOND_BONDED == m_oBluetoothDevice.getBondState())
            m_oBluetoothSocket = m_oBluetoothDevice.createRfcommSocketToServiceRecord(MY_UUID);     

            Log.i(TAG, "Socket Connected");

        catch(Exception e)
            if(null != m_oBluetoothSocket)
                Log.i(TAG, "Closing socket");
                catch (Exception e1) 
                    Log.i(TAG, "Error while closing socket : " + e1.getMessage());

I can create RFCOMMSocket using this code.

Now I want to send AT commands based on Bluetooth Hands-Free profile. e.g. If other mobile phone receives a phone call, my Android device can reject this call by sending AT command- “+CHUP”. I am not sure whether this is possible or not.

At this point, I am stuck. I have read Bluetooth APIs where I found –


Can we use this Intent for sending AT commands? Is this a proper way to send AT command based on Bluetooth Hands-Free profile? Please someone help me out and give me proper direction.

Any input from you all will be great help for me.

Thanks in advance.

How to&Answers:

You need to create InputStream and OutputStream so you can talk to the phone:

mmInStream = m_oBluetoothSocket.getInputStream();
mmOutStream = m_oBluetoothSocket.getOutputStream();

To setup the HFP connection you start to send:


Where 20 is code for what you support of HFP.

And to read from the phone:

buffer = new byte[200];
command = new String(buffer).trim();

So now you can talk beetwen the devices and you can read more about the Handsfree profile on https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=238193


Adding reference to AT commnads