一、耳机图标的显示效果如下图?
二,简单分析一下实现代码。实现代码在
?vendor\mediatek\proprietary\packages\apps\SystemUI\src\com\android\systemui\statusbar\phone\PhoneStatusBarPolicy.java,可以知道在接受到广播AudioManager.ACTION_HEADSET_PLUG后就更新图标。
?
三,模仿上面的耳机图标,添加一个自定义的图标。PhoneStatusBarPolicy.java修改的代码如下。
diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
old mode 100644
new mode 100755
index e3d5c08..2be9b9f
--- a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
+++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
@@ -107,6 +107,7 @@ public class PhoneStatusBarPolicy
private final String mSlotManagedProfile;
private final String mSlotRotate;
private final String mSlotHeadset;
+ private final String mTestHint;
private final String mSlotDataSaver;
private final String mSlotLocation;
private final String mSlotSensorsOff;
@@ -201,7 +202,9 @@ public class PhoneStatusBarPolicy
com.android.internal.R.string.status_bar_managed_profile);
mSlotRotate = resources.getString(com.android.internal.R.string.status_bar_rotate);
mSlotHeadset = resources.getString(com.android.internal.R.string.status_bar_headset);
- mSlotDataSaver = resources.getString(com.android.internal.R.string.status_bar_data_saver);
+ mTestHint = "testhint";
+
+ mSlotDataSaver = resources.getString(com.android.internal.R.string.status_bar_data_saver);
mSlotLocation = resources.getString(com.android.internal.R.string.status_bar_location);
mSlotSensorsOff = resources.getString(com.android.internal.R.string.status_bar_sensors_off);
mSlotScreenRecord = resources.getString(
@@ -221,6 +224,7 @@ public class PhoneStatusBarPolicy
IntentFilter filter = new IntentFilter();
filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
+ filter.addAction("android.intent.action.TESTHINT");
filter.addAction(Intent.ACTION_SIM_STATE_CHANGED);
filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
@@ -637,6 +641,16 @@ public class PhoneStatusBarPolicy
mIconController.setIconVisibility(mSlotHeadset, false);
}
}
+ private void updatetesthint(Intent intent) {
+ boolean connected = intent.getIntExtra("state", 0) != 0;
+ Log.d(TAG, "updatetesthint mTestHint connected:" + connected);
+ if (connected) {
+ mIconController.setIcon(mTestHint, R.drawable.stat_sys_hotspot, "testhintinfo");
+ mIconController.setIconVisibility(mTestHint, true);
+ } else {
+ mIconController.setIconVisibility(mTestHint, false);
+ }
+ }
@Override
public void onDataSaverChanged(boolean isDataSaving) {
@@ -681,6 +695,9 @@ public class PhoneStatusBarPolicy
case AudioManager.ACTION_HEADSET_PLUG:
updateHeadsetPlug(intent);
break;
+ case "android.intent.action.TESTHINT":
+ updatetesthint(intent);
+ break;
/// M: [Multi-User] Register Alarm intent by user @{
case Intent.ACTION_USER_SWITCHED:
updateAlarm();
四、adb 发广播,自定义的图标会显示出来,如第一个图右侧的第一个图标。系统里面可以通过广播的形式更新图标提示用户。
五、参考文章
Android在状态栏增加耳机拔插图标_lme525的专栏-CSDN博客
在状态栏增加图标(Android 6.0) - 快乐的铲屎官 - 博客园
|