The example in this article describes the Android implementation method for adding headphones status icons. Share to everyone for your reference. Specifically as follows:
The original eco-Android system is not indicated by a headset insert or insert status, this article explains how to add a headset insert status indicator. The effect chart is as follows
As shown in the figure, a headset icon appears on the status bar when the headset is plugged in.
This headset icon and SIM card signal icon on the right side of the status bar, so this implementation is certainly not implemented through notification, then add this function can only be found in the framwork inside. The specific steps to modify are as follows:
1. Add a stat_sys_headset.png resource file first in the frameworks/base/core/res/res/drawable-mdpi directory. The directory of the resource files is determined according to the resolution of the device, my device is HVGA, so the resource files are placed in the DRAWABLE-MDPI directory.
2. Modify Frameworks/base/services/java/com/android/server/status/statusbarpolicy.java
public class Statusbarpolicy {private static final String TAG = "Statusbarpolicy";
private static Statusbarpolicy sinstance;
...//alarm clock//Icon lit when clock is set private IBinder Malarmclockicon;
Private Icondata Malarmclockicondata;
Modify here start//headset private IBinder Mheadsetplugicon;
Private Icondata Mheadsetplugicondata; Modify here ... private broadcastreceiver mintentreceiver = new Broadcastreceiver () {@Override public void
OnReceive (context context, Intent Intent) {String action = intent.getaction ();
if (Action.equals (Intent.action_time_tick)) {updateclock ();
} ... else if (action.equals (intent.action_alarm_changed)) {updatealarm (Intent);
//modify here start else if (Action.equals (Intent.action_headset_plug)) {updateheadset (Intent);
//modify here-end else if (Action.equals (intent.action_sync_state_changed)) {updatesyncstate (Intent);
}
......
}; Private StatusBarpolicy (context context, Statusbarservice service) {Mcontext = context;
Mservice = Service;
Msignalstrength = new Signalstrength ();
if (Featureoption.mtk_gemini_support = = true) {Msignalstrengthgemini = new signalstrength ();
} mbatterystats = Batterystatsservice.getservice (); ...//modify here start//headset mheadsetplugicondata = Icondata.makeicon ("Headset", Null,com.android.inte Rnal.
R.drawable.stat_sys_headset, 0, 0);
Mheadsetplugicon = Service.addicon (mheadsetplugicondata, NULL);
Service.seticonvisibility (Mheadsetplugicon, false);
Modify here ....
Intentfilter filter = new Intentfilter ();
Register for Intent broadcasts for ... filter.addaction (Intent.action_time_tick);
....//modify here start filter.addaction (intent.action_headset_plug);
Modify here ...} Modify here start private final void Updateheadset (Intent Intent) {slog.d (TAG, "updateheadset:state=" + Intent.geti
Ntextra ("state", 0)); MserviCe.seticonvisibility (Mheadsetplugicon, (Intent.getintextra ("state", 0) = = 1)? true:false);
//modify here ...}
3. Modify Frameworks/base/core/res/res/values/arrays.xml
<string-array name= "Status_bar_icon_order" > <item><xliff:g id= "id" >clock</xliff:g></ Item> <item><xliff:g id= "id" >secure</xliff:g></item> <item><xliff:g id= "id" >alarm_clock</xliff:g></item> <item><xliff:g id= "id" >battery</xliff:g></item > <item><xliff:g id= "id" >phone_signal_2</xliff:g></item> <item><xliff:g id= "id ">phone_signal</xliff:g></item> <item><xliff:g id=" id ">phone_evdo_signal</xliff:g ></item> <item><xliff:g id= "id" >data_connection</xliff:g></item> <item> <XLIFF:G id= "id" >cdma_eri</xliff:g></item> <item><xliff:g id= "id" >tty</xliff:g ></item> <item><xliff:g id= "id" >volume</xliff:g></item> <item><xliff:g id= "id" >mute</xliff:g></item> <item><xliff:g id= "id" >Speakerphone</xliff:g></item> <!--modify here start. --> <item><xliff:g id= "id" >headset</xliff:g></item> <!--modify here-end--> <it EM><XLIFF:G id= "id" >wifi</xliff:g></item> <item><xliff:g id= "id" >tty</xliff:g ></item> <item><xliff:g id= "id" >bluetooth</xliff:g></item> <item><xliff : G id= "id" >gps</xliff:g></item> <item><xliff:g id= "id" >sync_active</xliff:g>< /item> <item><xliff:g id= "id" >sync_failing</xliff:g></item> <item><xliff:g id= "id" >ime</xliff:g></item> </string-array>
The "headset" string is "Mheadsetplugicondata = Icondata.makeicon" ("Headset", null0, 0); The first parameter in the The position of the statement "<item><xliff:g id=" id ">headset</xliff:g></item>" is related to where the icon appears on the status bar.
I hope this article will help you with your Android program.