admin管理员组文章数量:1624338
当蓝牙耳机配对成功后,会发送一个BONDING_STATE_CHANGE的消息,在BondStateMachine状态机里会对这个消息进行处理,调用setProfilePriorty(dev)函数对当前的耳机进行优先级的设置,
把以前的设置优先级顺序Hid、A2DP、Headset改为Headset、A2DP、Hid,请看这个函数修改后的具体code:
private void setProfilePriorty(BluetoothDevice device){
HidService hidService = HidService.getHidService();
A2dpService a2dpService = A2dpService.getA2dpService();
HeadsetService headsetService = HeadsetService.getHeadsetService();
if ((headsetService != null) &&
(headsetService.getPriority(device)== BluetoothProfile.PRIORITY_UNDEFINED)){
headsetService.setPriority(device,BluetoothProfile.PRIORITY_ON);
}
if ((a2dpService != null) &&
(a2dpService.getPriority(device) ==BluetoothProfile.PRIORITY_UNDEFINED)){
a2dpService.setPriority(device,BluetoothProfile.PRIORITY_ON);
}
if((hidService != null) &&
(hidService.getPriority(device) ==BluetoothProfile.PRIORITY_UNDEFINED)){
hidService.setPriority(device,BluetoothProfile.PRIORITY_ON);
}
}
会把当前耳机的Headset Profile 和A2DP Profile的优先级设置为PRIORITY_ON。
当蓝牙耳机连接成功时,processProfileStateChanged函数会调用 setProfileAutoConnectionPriority(device,profileId)函数设置优先级,看修改后这个函数的具体code:
void setProfileAutoConnectionPriority(BluetoothDevice device, int profileId){
HeadsetService hsService = HeadsetService.getHeadsetService();
A2dpService a2dpService =A2dpService.getA2dpService();
if ((hsService != null) &&
(BluetoothProfile.PRIORITY_AUTO_CONNECT !=hsService.getPriority(device))){
adjustOtherHeadsetPriorities(hsService,device);
hsService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT);
}
if ((a2dpService != null)&&
(BluetoothProfile.PRIORITY_AUTO_CONNECT != a2dpService.getPriority(device))){
adjustOtherSinkPriorities(a2dpService, device);
a2dpService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT);
}
}
会把当前耳机的Headset和A2DP的Profile优先级都设置为PRIORITY_AUTO_CONNECT,同时会把其他的耳机设备的优先级设为PRIORITY_ON,保证耳机自动连接优先级的设备只有一个。
蓝牙耳机自动连接过程:
当蓝牙打开时,如果有配对的蓝牙耳机存在,就会根据它的优先级,判断是否进行自动连接。如果优先级为PRIORITY_AUTO_CONNECT,该耳机就会自动进行连接。
---------------------
版权声明:本文为CSDN博主「就爱吃鲜橙」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn/OswinWang/article/details/60871463
版权声明:本文标题:蓝牙耳机Priority设置流程 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1728896156a1178435.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论