【发布时间】:2023-03-28 02:35:01
【问题描述】:
在 Android Oreo Android 8.0 中支持快捷图标上的徽章。
问题是,规范说即使用户从通知面板中删除了通知,我也需要保持徽章打开。
我该怎么做?
ShortcutBadger 无法在此手机上使用。
理论上,当我显示这个数字时,我会这样做:
api.getUnreadNotificationCount(unreadCount -> {
ShortcutBadger.applyCount(getApplicationContext(), unreadCount);
NotificationCompat.Builder groupBuilder = new NotificationCompat.Builder(CloudMessaging.this, pushNotificationModel.collapseKey == null ? getApplicationContext().getString(R.string.default_notification_channel_id) : pushNotificationModel.collapseKey)
.setSmallIcon(R.drawable.ic_notification)
.setAutoCancel(true)
.setSound(null)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setChannelId(getString(R.string.default_notification_channel_id))
.setGroup(remoteMessage.getCollapseKey())
.setGroupSummary(true)
.setNumber(unreadCount)
.setSubText(unreadCount + " new updates");
pushNotificationModel.summaryMessageId = 100;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
notificationManager.notify(pushNotificationModel.collapseKey, pushNotificationModel.summaryMessageId, groupBuilder.build());
}
});
不知何故WhatsApp 能够做到。
【问题讨论】:
-
您使用的是哪家公司的手机?
-
三星galaxy s9
-
布尔成功 = ShortcutBadger.isBadgeCounterSupported(this);在 applyCount 方法之前写下这一行并检查响应是否正确,而不是您的设备正在使用徽章。
-
请在问题中阅读我声明 ShortcutBadger 确实不支持这款手机,但 Whatsapp 确实支持这款手机,所以有办法,我只是不知道这是什么。你呢?
-
@Pratik18 他们的徽章看起来和所有其他徽章一模一样,我认为他们不是自己制作的……如果是,我该如何制作自己的?
标签: android push-notification badge