7

startForeground() need to create NotificationChannel so it will show badge number 1 on Launcher icon in Oreo devices

How can i hide/disable it programmatically?

Because Galaxy S8(Oreo) display badge number 1. And Android 8.0 emulator also display dot.

This is how i am doing now. But setShowBadge(false) not works

EDIT1:

        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        NotificationChannel tmpC = new NotificationChannel(id, "basic", NotificationManager.IMPORTANCE_MIN);
        tmpC.setShowBadge(false);

        manager.createNotificationChannel(tmpC);

        Notification notification = new NotificationCompat.Builder(this, id)
                .setChannelId(id)
                .setAutoCancel(true)
                .build();

        startForeground(getPackageName().hashCode(), notification);
Knowledge Drilling
  • 844
  • 1
  • 8
  • 19
  • Did you find a solution for this? – JBA Aug 05 '19 at 22:08
  • No, but my client app restarted foreground service whenever app finishes, that was core of the problem, and customers really hate it, because it show badge number 1 whenever close the app, that's how i told them to use remote service for the System.exit for the app. – Knowledge Drilling Aug 06 '19 at 00:47
  • Thank you. This is what worked for me: this badge setting cannot be changed without regenerating entirely the NotificationChannel. But even re-compiling the app from Android Studio did not refresh it curiously, however, killing the app and restarting it... did the trick. – JBA Aug 06 '19 at 06:16
  • If you really dare the risk of restarting your app, how about using deleteNotificationChannel api? – Knowledge Drilling Aug 06 '19 at 07:28
  • Any solution in 2020? – isabsent Apr 09 '20 at 11:23

2 Answers2

3

This answer is correct, but the point is you have to remove old version of the application by hands from Android "Applications" menu and install new version with mChannel.setShowBadge(false) on the clean device to get it working. An installation over the old version (where mChannel.setShowBadge(false) was absent) will not lead to the changing of the behaviour concerned with this badge.

isabsent
  • 3,219
  • 3
  • 21
  • 44
2

all you need to do is calling setShowBadge(false) on your NotificationChannel object.

NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

// Create notification channel.
NotificationChannel channel = new NotificationChannel({channel_id}, {name}, {importance});
mChannel.setShowBadge(false); // Disable badges for this notification channel.
mNotificationManager.createNotificationChannel(mChannel);

// Create notification and use channel
Notification notification = new NotificationCompat.Builder(context, {channel_id})
         ...
         .build();

// notify
mNotificationManager.notify({notification_id}, notification)

Check out Modify a Notification Badge.