简体   繁体   English

如何在android中的应用程序图标上显示徽章计数? ShortcutBadger 不起作用,我不想使用小部件

[英]How can i show the badge count on app icon in android? ShortcutBadger does not work, I don't want to use widget

I used ShortcutBadger library for android but it is not working in my case.我使用了适用于 android 的 ShortcutBadger 库,但它不适用于我的情况。 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. facebook whatsapp 之类的应用程序显示徽章计数,并且在我的手机中可见。 在此处输入图像描述

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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在应用程序图标或窗口小部件中显示徽章计数 - How do I show badge counts on the app icon or in widget 快捷Bad库没有在Android Studio中的应用程序图标上显示徽章计数 - Shortcut Badger library don't show up badge count on the app icon in Android Studio 我想在Android中的启动器图标上显示通知计数(徽章) - i want to display notification count (badge)on launcher icon in android 如何以编程方式在Android上的应用程序图标上显示推送通知徽章计数? - How to show push notification badge count on app icon in android programmatically? 如何增加 Android 应用程序上的徽章计数? - How can I increment badge count on Android App? 如何在启动图标上添加未读徽章计数? - How can I add a unread badge count on launch icon? 当我不想根据应用平台呈现小部件时,我应该使用 null 还是空 Container? - Should I use null or an empty Container when I don't want to render a widget according to the app platform? 我想在我的应用程序图标上显示未读通知计数 - I want to show unread notification count on my app icon 如何使用 Ionic 2 在 Android 应用程序图标中增加徽章计数通知? - How to increase badge count notification in the Android app icon using Ionic 2? 如何在后台在Android应用程序图标上计算推送通知消息徽章 - How to count Push notification message badge on android app icon in background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM