如何在Android中发送基于BT免提配置文件的AT命令?

我正在尝试通过免提配置文件在Android设备与其他手机之间建立蓝牙连接.我正在使用以下代码 –

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())
    {
        try
        {
            m_oBluetoothSocket = m_oBluetoothDevice.createRfcommSocketToServiceRecord(MY_UUID);     
            m_oBluetoothSocket.connect();

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

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

我可以使用此代码创建RFCOMMSocket.

现在我想发送基于蓝牙免提配置文件的AT命令.例如如果其他手机接到电话,我的Android设备可以通过发送AT命令 – “CHUP”拒绝此呼叫.我不确定这是否可能.

此时,我被卡住了.我已经阅读了蓝牙API,我发现 –

     BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT

我们可以使用此Intent发送AT命令吗?这是基于蓝牙免提配置文件发送AT命令的正确方法吗?请有人帮助我,给我正确的指导.

你们的任何意见对我都有很大的帮助.

提前致谢.

解决方法:

您需要创建InputStream和OutputStream,以便与电话通话:

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

要设置HFP连接,您可以开始发送:

mmOutStream.write("AT+BRSF=20\r".getBytes());

其中20是您支持HFP的代码.

并通过电话阅读:

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

所以现在你可以谈论设备,你可以在https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=238193上阅读有关免提配置文件的更多信息

上一篇:使Android 2.1上的蓝牙无限期可被发现


下一篇:openwrt蓝牙文件传输