我如何在Android中显示有关应用程序图标的徽章? shortcutbadger不起作用,我不想使用小部件

发布于 2025-02-01 13:34:04 字数 187 浏览 2 评论 0原文

我使用shortcutbadger库作为Android,但在我的情况下它不起作用。我在各种设备上对其进行了测试。我谷歌搜索了它,可能的解决方案可以是使用小部件。还有其他解决方案吗?诸如Facebook WhatsApp之类的应用显示徽章计数,并且在我的手机中可见。 /I.SSTATIC.NET/I3SSS.JPG“ ALT =”在此处输入图像说明”>

I used ShortcutBadger library for android but it is not working in my case. I tested it on various devices. I googled about it and possible solution can be use of widget. Is there any other solution? Apps like facebook whatsapp showing the badge count and that is visible in my phone.enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

同尘 2025-02-08 13:34:04

您可以使用自定义计数生成本地通知。
示例:

android doc android

var notification = NotificationCompat.Builder(this@MainActivity, CHANNEL_ID)
        .setContentTitle("New Messages")
        .setContentText("You've received 3 new messages.")
        .setSmallIcon(R.drawable.ic_notify_status)
        .setNumber(3)
        .build()

doc 强> Java:

Notification notification = new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
        .setContentTitle("New Messages")
        .setContentText("You've received 3 new messages.")
        .setSmallIcon(R.drawable.ic_notify_status)
        .setNumber(3)
        .build();

以下将触发通知。

NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, notificationBuilder.build());

you could generate the local notification with custom count.
example :

Android Doc

Kotlin:

var notification = NotificationCompat.Builder(this@MainActivity, CHANNEL_ID)
        .setContentTitle("New Messages")
        .setContentText("You've received 3 new messages.")
        .setSmallIcon(R.drawable.ic_notify_status)
        .setNumber(3)
        .build()

Java:

Notification notification = new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
        .setContentTitle("New Messages")
        .setContentText("You've received 3 new messages.")
        .setSmallIcon(R.drawable.ic_notify_status)
        .setNumber(3)
        .build();

following will trigger the notification.

NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, notificationBuilder.build());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文