技术标签: 蓝牙耳机 BT HFP A2DP Android
蓝牙耳机图标显示代码路径在:
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/
在PhoneStatusBarPolicy.java中的函数
private final void updateBluetooth(Intent intent) {
inticonId = R.drawable.stat_sys_data_bluetooth;
String contentDescription = null;
String action = intent.getAction();
if(action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,BluetoothAdapter.ERROR);
mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
}else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
BluetoothAdapter.STATE_DISCONNECTED);
if (state == BluetoothAdapter.STATE_CONNECTED) {
iconId = R.drawable.stat_sys_data_bluetooth_connected;
contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
}else {
contentDescription = mContext.getString(
R.string.accessibility_bluetooth_disconnected);
}
}else {
return;
}
mService.setIcon("bluetooth",iconId, 0, contentDescription);
mService.setIconVisibility("bluetooth", mBluetoothEnabled);
}
通过 updateBluetooth这个函数可以看到,蓝牙耳机的图标是根据广播 ACTION_CONNECTION_STATE_CHANGED来判断的。
下面我们来看一看广播ACTION_CONNECTION_STATE_CHANGED是如何发送的,
代码路径在:
packages/apps/Bluetooth/src/com/android/bluetooth/btservice
在AdapterProperties.java中的函数
void sendConnectionStateChange(BluetoothDevicedevice, int profile, int state, int prevState) {
......
synchronized (mObject) {
updateProfileConnectionState(profile,state, prevState);
if (updateCountersAndCheckForConnectionStateChange(state, prevState)) {
setConnectionState(state);
Intent intent = new Intent(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.putExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
convertToAdapterState(state));
intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_CONNECTION_STATE,
convertToAdapterState(prevState));
......
}
}
}
通过函数 sendConnectionStateChange来看广播的发送是由 updateCountersAndCheckForConnectionStateChange()函数的返回值决定的。
private booleanupdateCountersAndCheckForConnectionStateChange(int state, int prevState) {
switch (prevState) {
case BluetoothProfile.STATE_CONNECTING:
mProfilesConnecting--;
break;
case BluetoothProfile.STATE_CONNECTED:
mProfilesConnected--;
break;
case BluetoothProfile.STATE_DISCONNECTING:
mProfilesDisconnecting--;
break;
}
switch (state) {
case BluetoothProfile.STATE_CONNECTING:
mProfilesConnecting++;
return (mProfilesConnected == 0 && mProfilesConnecting == 1);
case BluetoothProfile.STATE_CONNECTED:
mProfilesConnected++;
return (mProfilesConnected == 1);
case BluetoothProfile.STATE_DISCONNECTING:
mProfilesDisconnecting++;
return (mProfilesConnected == 0 && mProfilesDisconnecting == 1);
case BluetoothProfile.STATE_DISCONNECTED:
return (mProfilesConnected == 0 && mProfilesConnecting == 0);
default:
return true;
}
}
通过updateCountersAndCheckForConnectionStateChange来看,mProfilesConnecting、mProfilesConnected、mProfilesDisconnecting这三个变量满足一定的条件函数返回才为TRUE。而这三个变量会根据连蓝耳机上次状态和当前状态的进行加减。
蓝牙耳机图标显示过程:
蓝牙耳机的连接分为Headset Profile 和A2DP Profile两个Profile,连接的时候只要有一个连接上就会返回TRUE,发送广播,从而显示蓝牙耳机图标,而断开连接的时候只有两个都断开了才会返回TRUE,发送广播,显示蓝牙普通图标。
最后的生成效果如下,如果不是想生成我这种效果的请绕路,如果想生成我这种效果的请仔细阅读每一个步骤,不然很可能生成不了,因为我也是按照其他教程尝试了很多次才实现的(初次使用 Idea,之前是eclipse用的比较多)。第一步:...
本文内容节选自6月21-23日,由msup和高可用社区联合主办的第五届 GIAC(全球互联网架构大会),中国联通网络技术研究院物联网技术研发中心总监胡云分享的《5G应用...
1.relative 相对定位 ,相对自身原来位置,原有空间保留,不会被挤占。宽度为父元素宽度,且宽度会撑大/缩小父元素宽度2.fixed 固定定位,实现某个元素在可视窗口的居中位置显示 1)给自身设置宽高; 2)给自身加position:fixed; 3)用margin向左移动自身宽度的一半,向上移动自身高度的一半;3.absolute 绝对定位 脱离文档流 寻找父级是否有相对定位如果有 根据父级定位 如果没有找到会忘记父级的父级寻找直到浏览器才会根据浏览..
前言如果你接触过 跨进程通信 (IPC),那么你对Binder一定不陌生虽然 网上有很多介绍 Binder的文章,可是存在一些问题:浅显的讨论Binder机制 或 一味讲解 Binder源码、逻辑不清楚,最终导致的是读者们还是无法形成一个完整的Binder概念本文采用 清晰的图文讲解方式,按照 大角度 -> 小角度 去分析Binder,即:先从 机制、模型的角度 去分析 整个Bi...
12年的时候写了些关于微信开发的内容,当时看好这个东西,可惜当时腾讯开放的权限太少,之后的一年多时间没有太关注了。 现在又要重新开始微信开发的阵容了,微信只是个入口,微网站才是趋势。 我是个水货,所以写的都是比较入门的,给初学者点启发用的。 这里有3个文件,一个页面展示(不贴代码了,就两个文本框和提交按钮)和后台代码,一个方法类,一个实体类 后台代码 protected void...
一、实验说明: 当一个任务正在运行的时候,由于某种情况可能需要终止运行一段时间,终止的这段时间就是所谓的任务的挂起,可以由该任务自身或者其他任务来挂起一个任务。当被挂起的任务需要再次运行的时候,可以恢复被挂起的任务。本实验中红灯和绿灯以固定频率闪烁,当任务寄存器的值达到5的时候,挂起绿灯闪烁任务,只剩下红灯闪烁,当任务寄存器的值达到10的时候,被挂起的绿灯闪烁任务恢复,红灯和...
步骤: 1.添加音乐控制插件 <!-- START:音乐控制 --> <plugin name="soundinterface" url="%SWFPATH%/plugins/soundinterface.swf" alturl="%SWFPATH%/plugins/soundinterface.js" rootpath="" preload=...
在jsp中,frameset标签的作用是在同一个窗口中布局多个页面。当同时写了frameset和body时,只会执行写在前面的一个,两者写其一即可。如<html> <frameset> </frameset> <body> </body></html>其中frameset会被执行,body不会被执行。...
如果在开发过程中遇到什么问题我会尽我所能,提供帮助;如果我遇到什么问题,也恳请大家帮忙!共同探讨,一起分享!
一篇文章解决jQuery快速入门,jQuery远远比你想象的简单!
前置文章: 《Android 4.4 KitKat Notif...
原文地址:http://dixq.net/rp/龙神录的 programming 馆龙神录的编程教室,是为了让谁都可以制作龙神录(仿东方的STG)的一个解说教学的地方。这里没有复杂的语句,使用初学者也能看懂的语言来介绍。只要有C语言的基本知识,和DxLib 的知识,谁都可以制作龙神录的!游戏编程教室的DxLib 使用熟练后,现在我们就来制作真正的游戏吧。接下来,