在这里,我尝试使用经典蓝牙连接两个 Android 设备,并通过 HFP 配置文件转接呼叫。
如果设备A有来电,我需要通知设备B并从设备B端接受/拒绝,甚至需要从设备B端通话。
我在蓝牙配置中从源端进行了更改,以便为设备 B 中的 HFP 配置文件启用 A2DP 接收器和 HF 角色(禁用 AG 角色)。
我对 AT 命令的工作原理感到困惑。我必须通过输出流传递 AT 命令(蓝牙经典连接)。
仅传递 AT 命令(根据 HFP 文档)来接受呼叫就足够了,还是我必须根据收到的 AT 命令在设备 B 端处理呼叫?我正在为此工作创建一个应用程序。
如果通过 AT 命令接受呼叫,呼叫也会自动通过连接进行传输,或者我是否必须从应用程序级别手动执行某些操作?
Android框架对HFP提供了良好的支持。
至于如何扮演HF角色:
private BluetoothHeadsetClient mBluetoothHeadsetClient;
private final ServiceListener mHfpServiceListener = new ServiceListener() {
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile == BluetoothProfile.HEADSET_CLIENT) {
mBluetoothHeadsetClient = (BluetoothHeadsetClient) proxy;
}
}
@Override
public void onServiceDisconnected(int profile) {
if (profile == BluetoothProfile.HEADSET_CLIENT) {
mBluetoothHeadsetClient = null;
}
}
};
mAdapter.getProfileProxy(context.getApplicationContext(), mHfpServiceListener,
BluetoothProfile.HEADSET_CLIENT);
mBluetoothHeadsetClient.connect(remoteDevice)
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothHeadsetClient.ACTION_AG_EVENT);
mContext.registerReceiver(this, filter);
filter.addAction(BluetoothHeadsetClient.ACTION_CALL_CHANGED);
mContext.registerReceiver(this, filter);
mBluetoothHeadsetClient.dail
mBluetoothHeadsetClient.acceptCall
mBluetoothHeadsetClient.sendVendorAtCommand
Android提供高级API,您无需发送AT命令即可接受呼叫。