I used to show a number in app icon using this library as follows:
ShortcutBadger.applyCount(context, numberToShow);
OneSignal also has same function in its Android SDK.
Now in Oreo, with the introduction of notification channels, things get complex to me. I can create a channel. Then, I can also create a notification as follows:
public static void createNotification(Context context, int numberToShow) {
Notification notification = new NotificationCompat.Builder(context, context.getString(R.string.notification_channel_id))
.setContentTitle("Dummy Title")
.setContentText("Dummy content")
.setSmallIcon(R.drawable.app_icon)
.setNumber(numberToShow)
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(0, notification);
}
However, I have to show a notification with this solution, which I don't need and thus don't want. Is there any way in Oreo that I can achieve the same thing I have done previously, i.e. just showing 'notification dot' or a number attached to the app icon?
Dot-style badge and notification preview option are newly added in Oreo OS. To change to badge with a number, follow these steps: 2 Tap Notifications. 3 Tap App icon badges. 4 Select Show with number. Is this content helpful? Get product support via live chat, email, and more.
By default, notification badges are enabled in Android Oreo. But some Android vendors may disable it by default. You can enable or disable notification dots in the Settings. For example, you can enter phone settings through the quick settings panel as shown below. In the Settings page, tap apps & notification as shown below.
But number badge is Samsung’s proprietary implementation. Only apps that implemented some Samsung libraries will have this number badge feature. Notification dots in Android Oreo works with all apps. Even the app was developed (targeted) for old versions of Android, Android Oreo is able to show notification dots (notification badges).
It only works with selected apps because it does not use standard Android hooks. In Android Oreo update (with Samsung Experience 9.0), Samsung abandoned the old approach and switched to notification dots (with number option kept) in stock Android. So, this number badge is different from that in the old versions.
Sorry, but there is no SDK-level support for showing numbers or other badges on launcher icons, other than the Notification
scenario that you described.
set the importance of the notification channel to
IMPORTANCE_MIN
like int importance = NotificationManager.IMPORTANCE_MIN;
and then create the channel as -
NotificationChannel nChannel = new NotificationChannel
(channelId, title, importance);
This will the set the badge count(shown on the long press of the icon) without notifying the user about any notification in the system tray. Though the notification will be in the tray, but will not pop up and quietly reside there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With