как сохранить значок уведомления на - PullRequest
0 голосов
/ 16 декабря 2018

В 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 может это сделать.

1 Ответ

0 голосов
/ 22 декабря 2018

Попробуйте этот код,

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  builder.setChannelId(NOTIFICATION_CHANNEL);
  NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, "Badger Sample",
  NotificationManager.IMPORTANCE_DEFAULT);
  channel.setShowBadge(true);
  mNotificationManager.createNotificationChannel(channel);
 }

удалить ниже строки

ShortcutBadger.applyCount(getApplicationContext(), unreadCount);
...