我试图建立与其他手机在免提模式Android设备之间的蓝牙连接。我使用下面的code -
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())
{
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());
}
}
}
}
}
我可以用这个code创建RFCOMMSocket。
I can create RFCOMMSocket using this code.
现在我要发送AT命令基于蓝牙免提模式。例如如果其他的手机收到一个电话,我的Android设备可以通过发送AT命令 - + CHUP拒绝这一呼吁。我不知道这是否是可以或不可以。
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.
在这一点上,我坚持。我已阅读蓝牙API的,我发现 -
At this point, I am stuck. I have read Bluetooth APIs where I found -
BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT
我们可以用这个意向发送AT命令?这是发送AT命令基于蓝牙免提模式之有道?请人帮助我,并给我正确的方向。
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.
在此先感谢。
推荐答案
您需要创建InputStream和OutputStream这样你就可以交谈的电话:
You need to create InputStream and OutputStream so you can talk to the phone:
mmInStream = m_oBluetoothSocket.getInputStream();
mmOutStream = m_oBluetoothSocket.getOutputStream();
要设置HFP连接开始传送:
To setup the HFP connection you start to send:
mmOutStream.write("AT+BRSF=20r".getBytes());
其中20为code为你支持HFP的。
Where 20 is code for what you support of HFP.
和从手机阅读:
buffer = new byte[200];
mmInStream.read(buffer);
command = new String(buffer).trim();
所以,现在你可以跟beetwen的设备,你可以阅读更多有关的 https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=238193
相关推荐
最新文章