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.
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.
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.
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).
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With