[英]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 :例子 :
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.