Show LevelListDrawable in notification bar

I am trying to show an icon in the notification bar. The icon is a LevelListDrawable, which can change content by setting levels. The question is, I cannot set the icon level in the notification. I tried using "Notification.icon" and "Notification.iconLevel" but it doesn't work.

Here is my code snippet. can anyone see what is wrong?

Notification notification = new Notification(R.drawable.ic_stat_notify, "", System.currentTimeMillis());
notification.icon = R.drawable.ic_stat_notify;
notification.iconLevel = 30;
notification.setLatestEventInfo(context, "Hello", "World", intent);
manager.notify(NOTIFICATION_ID, notification);

      

Here is my LevelListDrawable

?xml version="1.0" encoding="utf-8"?>
level-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/ic_stat_notify_0"
        android:minLevel="0"
        android:maxLevel="9"/>
    <item android:drawable="@drawable/ic_stat_notify_10"
        android:minLevel="10"
        android:maxLevel="11"/>
    <item android:drawable="@drawable/ic_stat_notify_20"
        android:minLevel="20"
        android:maxLevel="29"/>
    <item android:drawable="@drawable/ic_stat_notify_30"
        android:minLevel="30"
        android:maxLevel="39"/>
    <item android:drawable="@drawable/ic_stat_notify_40"
        android:minLevel="40"
        android:maxLevel="49"/>
    <item android:drawable="@drawable/ic_stat_notify_50"
        android:minLevel="50"
        android:maxLevel="59"/>
    <item android:drawable="@drawable/ic_stat_notify_60"
        android:minLevel="60"
        android:maxLevel="69"/>
    <item android:drawable="@drawable/ic_stat_notify_70"
        android:minLevel="70"
        android:maxLevel="79"/>
    <item android:drawable="@drawable/ic_stat_notify_80"
        android:minLevel="80"
        android:maxLevel="89"/>
    <item android:drawable="@drawable/ic_stat_notify_90"
        android:minLevel="90"
        android:maxLevel="99"/>
    <item android:drawable="@drawable/ic_stat_notify_100"
        android:minLevel="100"
        android:maxLevel="100"/>
</level-list>

      

+3


source to share


2 answers


If you want to display a specific icon for a notification in the extended notification list, you have to create a notification with a "normal" drawing without the icon and on the first update you can set a different icon (like a level list). and set the iconLevel.

To update the status bar icon



    notification.icon = R.drawable.ic_stat_notify;
    notification.iconLevel = 30;
    manager.notify(NOTIFICATION_ID, notification);

      

it is important to call notify () to make the updates visible, and will not update the icon in the expanded list unless you recreate the notification.

+1


source


This is a possible duplicate of this: android Notification setSmallIcon with level sheet



This seems to be a bug in Android. When you update a notification using the level list, the status icon is updated, but the icon is not present in the notification dropdown. It says here: http://code.google.com/p/android/issues/detail?id=43179&q=setSmallIcon&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

0


source







All Articles