Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It is possible to change the Icon of the status bar (notification icon) dynamically?

I have an android APP, with a lot of activities.

In the login activiti of my app, i start a notification icon in the status bar, and it is fixed there until my app stops. Ok, it works.

But now i need one more thing, i need to changue the icon dynamically, programatically, with a service of my app. How can i do it?

How can i access to the notification icon of my app and then change the icon?

I would appreciate code examples to illustrate how to achieve this.

like image 657
NullPointerException Avatar asked Jan 21 '11 11:01

NullPointerException


People also ask

How do I change my status bar icon?

To customize it, first pull down the slider bar from the top of the screen. Next, tap on the three vertical dots in the top right corner. Now click on Status bar. You're in.

Can you change the color of the status bar Android?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar. Step 3: In your MainActivity, add this code in your onCreate method.


2 Answers

Just call notify() again on NotificationManager with a new Notification but the same unique ID as you used for the first one. It will replace your icon of the existing Notification (or display the new Notification if the user cleared the first one).

like image 150
CommonsWare Avatar answered Sep 25 '22 07:09

CommonsWare


You could use the iconLevel on the Notification: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#More

Create a xml file in res/drawable/myicon.xml with different level (different icon) http://developer.android.com/reference/android/graphics/drawable/LevelListDrawable.html

<level-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:maxLevel="0" android:drawable="@drawable/ic_wifi_signal_1" />
  <item android:maxLevel="1" android:drawable="@drawable/ic_wifi_signal_2" />
  <item android:maxLevel="2" android:drawable="@drawable/ic_wifi_signal_3" />
</level-list>

and set or (update) the level with:

Notification mNotification = new Notification(icon, tickerText, when);
mNotification.iconLevel = 1;
mNoticationManager.notify(NOTIFICATION_ID, mNotification);
like image 32
user511564 Avatar answered Sep 24 '22 07:09

user511564