1

Since Android 8 all the notification should be assigned to some NotificationChannel. The issue in my case is that the app has more than one launcher, and the badges are displaying over each of them.

So I can disable badges for each NotificationChannel but anyway they can be turned on by the user.

Is it possible to connect 'NotificationChannel' to the specific launcher Activity? I haven't found any existed API nor any mention that it's a limitation for now.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
amukhachov
  • 5,822
  • 1
  • 41
  • 60

1 Answers1

0

you can disable the badges per channel eg. with mChannel.setShowBadge(false)

Sets whether notifications posted to this channel can appear as application icon badges in a Launcher. Only modifiable before the channel is submitted to NotificationManager.createNotificationChannel(NotificationChannel).

... when having having assigned some channelId to the NotificationChannel.

methods setGroup()  / getGroup()  and canShowBadge()  also appear relevant.

therefore you'd have to define channels per launcher (or at least two, in order to have at least one channel which shows no badges) - then you can disable the badges for some of them, depending into which channel the notifications are being sent.

there also is NotificationCompat.Builder(Context context, String channelId)

method .setShortcutId (String shortcutId):

If this notification is duplicative of a Launcher shortcut, sets the id of the shortcut, in case the Launcher wants to hide the shortcut.

LauncherApps can provide access to these shortcuts;

and one can at least get the badge icon from ShortcutInfo.

there's android.intent.action.BADGE_COUNT_UPDATE for stock Android Oreo.

currently, only the Sony launcher would permit defining the Activity with com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Thanks, I know it. But a user can turn it on back. – amukhachov Aug 21 '18 at 11:42
  • Correct, the original question is right about how to "define channels per launcher" – amukhachov Aug 21 '18 at 11:45
  • @birdy I've just hit save while writing sometimes.; and added `android-oreo` tag. and one can not directly define the channels per launcher, but only per notification - nevertheless, each single launcher activity could have their own channel (which might be useless complexity), depending which notification (with the associated notification channelId) one uses, one can route the these notification per activity... into at least two channels, eg. one with badges and one without. – Martin Zeitler Aug 21 '18 at 11:49
  • In my case, there are 3 NotificationChannels and 2 Activities. Channel1 is for Activity1, Channel2 is for Activity2, and Channel3 for the notifications without badges. The issue is that when Channel1 is receiving a notification - badge is updated over both Activity1 and Activity2 – amukhachov Aug 21 '18 at 11:58
  • @birdy think I've just found the method you were looking for... see the updated answer. honestly, I have no clue what to set as the `shortcutId`, but the terms `launcher` and `dupe` do sound reasonable. – Martin Zeitler Aug 21 '18 at 12:10
  • Shortcuts that's about the other functionality: https://developer.android.com/guide/topics/ui/shortcuts/ – amukhachov Aug 21 '18 at 12:40
  • 1
    @birdy those shortcuts are still quite close... but somehow there is no way to control which launcher icon will display those badges (since one cannot even access these buttons); you could only file a feature request for `androidx`: https://issuetracker.google.com/issues?q=componentid:192731 (possibly this is per design, but possibly this just had not been considered). it seems as if these notifications were internally dispatched per package name, not per launcher activity; so there's no way to differ. – Martin Zeitler Aug 21 '18 at 12:50