效果如图:
一、 在frameworks/base/packages/SystemUI/res/values/strings.xml 里添加
<string name="headset_enabled">Headset Enabled.</string>
二、 在fameworks/base/core/res/res/values/config.xml 里相应位置添加:
@@ -45,6 +45,7 @@ <item><xliff:g id="id">alarm_clock</xliff:g></item> <item><xliff:g id="id">secure</xliff:g></item> <item><xliff:g id="id">clock</xliff:g></item>+ <item><xliff:g id="id">headset</xliff:g></item> </string-array>
上面带+号的行为添加的
三、 frameworks/base/packages/SystemUI/res/drawable-xhdpi 或者你手机对应的分辨率的文件夹下添加stat_sys_headset.png和stat_sys_headset_mic.png
两个图片, 分别表示不带mic的耳机和带mic的耳机, 这两个图标将在状态栏显示, 图片可以自己找,也可以从fameworks/base/core/res/res/drawable-xhdpi里面提取现成的
四、 在frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java 打上下面的补丁:
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java@@ -103,6 +103,9 @@ public class PhoneStatusBarPolicy { else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) { updateTTY(intent); }+ else if (action.equals(Intent.ACTION_HEADSET_PLUG)) {+ updateHeadset(intent);+ } } }; @@ -119,6 +122,7 @@ public class PhoneStatusBarPolicy { filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION);+ filter.addAction(Intent.ACTION_HEADSET_PLUG); mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); int numPhones = MSimTelephonyManager.getDefault().getPhoneCount();@@ -276,4 +280,29 @@ public class PhoneStatusBarPolicy { mService.setIconVisibility("tty", false); } }++ private final void updateHeadset(Intent intent) {+ final String action = intent.getAction();+ final int state = intent.getIntExtra("state", 4);+ final int mic = intent.getIntExtra("microphone", 4);++ switch (state) {+ case 0:+ try{+ mService.setIconVisibility("headset", false);+ } catch (Exception e) {+ //Log.i("StatusBar Headset", "frist time to run");+ }+ break;+ case 1:+ if (mic == 1)+ mService.setIcon("headset", R.drawable.stat_sys_headset_mic, 0,+ mContext.getResources().getString(R.string.headset_enabled));+ else+ mService.setIcon("headset", R.drawable.stat_sys_headset, 0,+ mContext.getResources().getString(R.string.headset_enabled));+ mService.setIconVisibility("headset", true);+ break;+ }+ } }
如果有需要我可以提供smali版本的补丁!