本文共 1911 字,大约阅读时间需要 6 分钟。
a) 代码在系统中的位置
status bar 的相关代码位于:frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar。 其中PhoneStatusBarPolicy类主要负责接收action动作。frameworks\base\services\java\com\android\server
其他一些核心操作全部位于StatusBarManagerService类里面。
b) 在frameworks\base\core\res\res\values\config.xml中定义需要显示的Icon 的配置信息
c) 在frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\PhoneStatusBarPolicy.java 中初始化
// Alarm clock
mService.setIcon("alarm_clock", R.drawable.stat_sys_alarm, 0, null); mService.setIconVisibility("alarm_clock", false);// Sync state
mService.setIcon("sync_active", R.drawable.stat_sys_sync, 0, null); mService.setIcon("sync_failing", R.drawable.stat_sys_sync_error, 0, null); mService.setIconVisibility("sync_active", false); mService.setIconVisibility("sync_failing", false);
d) 在frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\PhoneStatusBarPolicy.java 中注册相应的receiver 来接受intent
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_ALARM_CHANGED)) { updateAlarm(intent); } else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) { updateSyncState(intent); } else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) || action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { updateBluetooth(intent); } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) || action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) { updateVolume(); } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { updateSimState(intent); } else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) { updateTTY(intent); } // [SystemUI] Support "Headset icon". { else if (action.equals(Intent.ACTION_HEADSET_PLUG)) { updateHeadSet(intent); } // [SystemUI] Support "Headset icon". } } };转载地址:http://prfsi.baihongyu.com/