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

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

概述我正在尝试通过免提配置文件在Android设备与其他手机之间建立蓝牙连接.我正在使用以下代码–privatestaticfinalUUIDMY_UUID=UUID.fromString("0000111F-0000-1000-8000-00805F9B34FB");//UUIDforHandsfreeprofile//Somecode...//GetBluetoothAdapter.

我正在尝试通过免提配置文件在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中发送基于BT免提配置文件的AT命令?全部内容,希望文章能够帮你解决如何在Android中发送基于BT免提配置文件的AT命令?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1101442.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存