android蓝牙hfp client使用例
1、首先确认配置文件是否开启hfp profile功能。根据设备的角色(hfp client / hfp server)来配置hfp profile.
profile 配置文件路径:
packages/apps/Bluetooth/res/values/config.xml
e.g. 设备的角色定义为hfp client,需做如下配置:
<bool name="profile_supported_hs_hfp">false</bool>
<bool name="profile_supported_hfpclient">true</bool
接下来看一下hfp client的实现,以accept call为例
2、步获取hfp client service
1) BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
2) mAdapter.getProfileProxy(getApplicationContext(),new MServerListener(), BluetoothProfile.HEADSET_CLIENT);
3) public class MServerListener implements ServiceListener {
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile == BluetoothProfile.HEADSET_CLIENT ) {
mclient=(BluetoothHeadsetClient)proxy ;
.......
}
}
3、 app获取hfp client service 的proxy之后,就可以直接调用相应的API进行连接控制与call 控制 。e.g.
mclient.connect ( device) //Connects to remote device.
mclient.connectAudio () //Initiates a connection of audio channel, set up SCO channel
mclient.acceptCall (device,0);
mclient.rejectCall (device);
mclient.terminateCall (device,0);
4、android hfp 对外API:
frameworks/base/core/java/android/bluetooth/
BluetoothHeadsetClientCall.aidl
BluetoothHeadsetClientCall.java
BluetoothHeadsetClient.java
BluetoothHeadset.java
IBluetoothHeadset.aidl
IBluetoothHeadsetClient.aidl
IBluetoothHeadsetPhone.aidl
e.g.
BluetoothHeadsetClient.acceptCall()
5、android hfp client services
packages\apps\bluetooth\src\com\android\bluetooth\hfpclient
HeadsetClientHalConstants.java
HeadsetClientService.java
HeadsetClientStateMachine.java
e.g. send msg to state machine and handle these msg
boolean acceptCall(BluetoothDevice device, int flag) {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
int connectionState = mStateMachine.getConnectionState(device);
if (connectionState != BluetoothProfile.STATE_CONNECTED &&
connectionState != BluetoothProfile.STATE_CONNECTING) {
return false;
}
Message msg = mStateMachine.obtainMessage(HeadsetClientStateMachine.ACCEPT_CALL);
msg.arg1 = flag;
mStateMachine.sendMessage(msg);
return true;
}
private void acceptCall(int flag, boolean retry) {
......
if (handleCallActionNative(action, 0)) {
addQueuedAction(ACCEPT_CALL, action);
} else {
Log.e(TAG, "ERROR: Couldn't accept a call, action:" + action);
}
}
6、enter native layter
packages/apps/Bluetooth/jni
com_android_bluetooth_hfpclient.cpp
com_android_bluetooth_hfp.cpp
e.g.
static jboolean handleCallActionNative(JNIEnv *env, jobject object, jint action, jint index) {
bt_status_t status;
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
if ( (status = sBluetoothHfpClientInterface->handle_call_action((bthf_client_call_action_t)action, (int)index)) != BT_STATUS_SUCCESS) {
ALOGE("Failed to enter private mode, status: %d", status);
}
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
//get bt stack profile interface
static void initializeNative(JNIEnv *env, jobject object) {
......
if ( (btInf = getBluetoothInterface()) == NULL) {
ALOGE("Bluetooth module is not loaded");
return;
}
sBluetoothHfpClientInterface = (bthf_client_interface_t *)
btInf->get_profile_interface(BT_PROFILE_HANDSFREE_CLIENT_ID);
if (sBluetoothHfpClientInterface == NULL) {
ALOGE("Failed to get Bluetooth HFP Client Interface");
return;
}
}
7、enter bt stack
external/bluetooth/bluedroid/bta/hf_client
bta_hf_client_act.c
bta_hf_client_api.c
bta_hf_client_at.c
bta_hf_client_at.h
bta_hf_client_cmd.c
bta_hf_client_int.h
bta_hf_client_main.c
bta_hf_client_rfc.c
bta_hf_client_sco.c
bta_hf_client_sdp.c
e.g. send AT cmd ATA to accept this call
handle_call_action(bthf_client_call_action_t action, int idx){
......
case BTHF_CLIENT_CALL_ACTION_ATA:
BTA_HfClientSendAT(btif_hf_client_cb.handle, BTA_HF_CLIENT_AT_CMD_ATA, 0, 0, NULL);
break;
}
android蓝牙hfp client使用例相关推荐
- Android 蓝牙 HFP sco 和esco链路的异同分析
同学,别退出呀,我可是全网最牛逼的 Android 蓝牙分析博主,我写了上百篇蓝牙文章,请点击下面了解本专栏,进入本博主主页看看再走呗,一定不会让你后悔的,记得一定要去看主页置顶文章哦. ...
- Android 蓝牙hfp协议连接slc连接rfcomm连接源码分析(2)- HF侧发送和接受数据流程
android-蓝牙A2dp-avrcp-hfp-opp-配对流程-ble-rfcomm源码流程 Android 蓝牙hfp初始化.rfcomm连接.slc连接.sco连接源代码分析大全 - 点击下载 ...
- Android 蓝牙 HFP 和 A2DP
Android 蓝牙 HFP 和 A2DP HFP(Hands Free Profile)和 A2DP (Advanced Audio Distribution Profile) 是经典蓝牙常用的两个 ...
- Android 蓝牙 HFP HF端的通话建立过程(framework)(二)
同学,别退出呀,我可是全网最牛逼的 Android 蓝牙分析博主,我写了上百篇蓝牙文章,请点击下面了解本专栏,进入本博主主页看看再走呗,一定不会让你后悔的,记得一定要去看主页置顶文章哦. Androi ...
- Android蓝牙开发【六】hfp连接
本文主要内容是蓝牙手机音频的连接.断开流程分析,对应蓝牙HFP profile. 该文章是基于Android源码4.3的 1 hfp简单介绍 HFP (Hands-free Profile),让蓝牙设 ...
- Android 蓝牙启动流程(以及设置蓝牙为作为sink模式 接收端模式)
本文以Android 7.1为基础 最近在做蓝牙开发,研究了一下蓝牙的启动流程,总结一下 Google在Android源码中推出了它和博通公司一起开发的BlueDroid以替代BlueZ.BlueZ的 ...
- ym——物联网入口之中的一个Android蓝牙4.0
转载请注明本文出自Cym的博客(http://blog.csdn.net/cym492224103),谢谢支持! 假设还有同学不知道蓝牙4.0能够做什么请查看Android+蓝牙 4.0 将带来什么? ...
- Android蓝牙服务
From 蓝牙服务 通过蓝牙,设备可以传输数据并供各种交互式服务(例如音频.短信和电话)使用.您可以在以下位置找到用于不同服务的蓝牙配置文件: include/hardware/bluetooth.h ...
- android -- 蓝牙 bluetooth (四)OPP文件传输
原址 在前面android -- 蓝牙 bluetooth (一) 入门文章结尾中提到了会按四个方面来写这系列的文章,前面已写了蓝牙打开和蓝牙搜索,这次一起来看下蓝牙文件分享的流程,也就是蓝牙应用op ...
最新文章
- visio 画类图时 方法里如何加参数
- pb设置Oracle事务的隔离级别,Oracle的事务隔离级别
- 干货整理及PPT下载福利 2017(上海)人工智能产品经理大会
- node更新到最新版本_win10怎么更新flash到最新版本「系统天地」
- easyUI validate函数【总结篇-部分转】
- CentOS 6.2 安装教程
- vscode代码库登录配置_VSCode 配置 Sonar Lint支持代码检查提效
- 我们为什么都应该坚持写博客,意义何在?
- Asp.net通过Gmail发送邮件
- virsh 关机_kvm 虚拟化 virsh shutdown 无法关闭虚拟机
- Office2010安装出现“错误1907”的解决方法(未验证)
- Android WebView无法播放视频或直播,关闭界面后任在播放的问题;
- 内核功能导致重启_错误信息:VS2010 Profiler导致Win7重启
- Android小说阅读器案例
- 帝国CMS 7.5仿《讲历史网》模板/优秀的历史网帝国CMS模板下载
- HTML5七夕情人节表白网页(爱情树 Html5实现唯美表白动画代码) HTML+CSS+JavaScript
- 阿里云ECS服务器安装AMH5.3面板并搭建WordPress站点详细教程(卞懂的学习笔记)...
- Python生成迷宫
- 一款可以帮助你处理文字、编写内容等办公软件-Word 2013 提供下载
- AIoT(人工智能+物联网)知识总结+实战项目