Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set badge count in Oreo without showing a notification?

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?

like image 832
Mehmed Avatar asked Aug 27 '18 10:08

Mehmed


People also ask

How to change to badge with a number in Oreo OS?

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.

How to enable or disable Notification badges in Android Oreo?

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.

What is the difference between number badge and Notification Dots?

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).

Why does the number badge only work with selected apps on Android?

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.


2 Answers

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.

like image 78
CommonsWare Avatar answered Nov 12 '22 19:11

CommonsWare


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.

like image 37
Krishna Avatar answered Nov 12 '22 19:11

Krishna