1

Problem Statement-

I am rendering a custom notification. If for some reason, the notification could not be rendered because of any exception (suppressed by Android), even after that, if I use NotificationManager.getActiveNotifications(), it gives me that notification that is not visible to the users.

To reproduce this issue-

I used an icon in the notification (using getApplicationInfo().icon in the setSmallIcon()) and the icon resource was removed intentionally from the resources folder.

Now, when notify() is called, I confirmed that the notification was not shown to the user because the icon resource is missing and the exception is handled/suppressed internally.

Icon    : Unable to load resource 0x7f0c0000 from pkg=com.tester.app
05-28 16:13:59.505  5442  5442 E Icon    : android.content.res.Resources$NotFoundException: Drawable com.tester.app:mipmap/ic_launcher with resource ID #0x7f0c0000
05-28 16:13:59.505  5442  5442 E Icon    : Caused by: android.content.res.Resources$NotFoundException: File res/mipmap-anydpi-v26/ic_launcher.xml from drawable resource ID #0x7f0c0000
05-28 16:13:59.505  5442  5442 E Icon    :  at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:1090)
05-28 16:13:59.505  5442  5442 E Icon    :  at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:791)
05-28 16:13:59.505  5442  5442 E Icon    :  at android.content.res.Resources.loadDrawable(Resources.java:1098)
05-28 16:13:59.505  5442  5442 E Icon    :  at android.content.res.Resources.getDrawableForDensity(Resources.java:1046)
05-28 16:13:59.505  5442  5442 E Icon    :  at android.content.res.Resources.getDrawable(Resources.java:985)
05-28 16:13:59.505  5442  5442 E Icon    :  at android.graphics.drawable.Icon.loadDrawableInner(Icon.java:381)
05-28 16:13:59.505  5442  5442 E Icon    :  at android.graphics.drawable.Icon.loadDrawable(Icon.java:334)
05-28 16:13:59.505  5442  5442 E Icon    :  at android.graphics.drawable.Icon.loadDrawableAsUser(Icon.java:456)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.StatusBarIconView.getIcon(StatusBarIconView.java:464)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.StatusBarIconView.getIcon(StatusBarIconView.java:448)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.StatusBarIconView.updateDrawable(StatusBarIconView.java:426)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.StatusBarIconView.set(StatusBarIconView.java:386)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.notification.icon.IconManager.setIcon(IconManager.kt:249)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.notification.icon.IconManager.createIcons(IconManager.kt:123)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinderImpl.inflateViews(NotificationRowBinderImpl.java:148)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.notification.NotificationEntryManager.addNotificationInternal(NotificationEntryManager.java:619)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.notification.NotificationEntryManager.addNotification(NotificationEntryManager.java:646)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.notification.NotificationEntryManager$2.onNotificationPosted(NotificationEntryManager.java:386)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.NotificationListener.lambda$onNotificationPosted$1(NotificationListener.java:131)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.NotificationListener.lambda$onNotificationPosted$1$NotificationListener(Unknown Source:0)
05-28 16:13:59.505  5442  5442 E Icon    :  at com.android.systemui.statusbar.-$$Lambda$NotificationListener$NvFmU0XrVPuc5pizHcri9I0apkw.run(Unknown Source:6)

Now, when I call getActiveNotifications(), it contains the same notification (filtered via a unique notification id) that I added (which was not rendered).

As per my understanding from the documentation, it should only return active notifications of the calling app which are not dismissed by the user or cancelled by the system.

Tried many solutions. A few links I referred to-

  1. https://developer.android.com/reference/android/app/NotificationManager#getActiveNotifications()
  2. https://developer.android.com/reference/android/service/notification/NotificationListenerService
  3. Is it possible to check if a notification is visible or canceled?
  4. Getting statusbar notifications using notificationManager.getActiveNotifications()
  5. https://medium.com/@krossovochkin/android-notifications-overview-and-pitfalls-517d1118ec83
  6. https://automationchronicles.com/how-to-get-displayed-notifications-on-android/
Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121

0 Answers0