Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i hide badge count number when startForeground()

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);
like image 630
Knowledge Drilling Avatar asked Feb 01 '19 03:02

Knowledge Drilling


People also ask

How do I hide badges on Android?

If your Samsung Galaxy smartphone runs Android 11 or 12, open the Settings app and head into the "Notifications" menu. Then, tap "Advanced settings" and toggle off the "App icon badges" switch.

How do I get an unread notification count on Android?

If you want to change badge with number, you can be changed in NOTIFICATION SETTING on the notification panel or Settings > Notifications > App icon badges > Select Show with number.


2 Answers

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.

like image 88
EffectiveMatrix Avatar answered Nov 07 '22 02:11

EffectiveMatrix


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.

like image 33
isabsent Avatar answered Nov 07 '22 03:11

isabsent