Как я могу скрыть номер счетчика значков, когда startForeground () - PullRequest
0 голосов
/ 01 февраля 2019

startForeground () необходимо создать NotificationChannel, чтобы он отображал значок № 1 на значке запуска в устройствах Oreo

Как я могу скрыть / отключить его программным способом?

Потому что Galaxy S8 (Oreo)Отображать значок № 1. И Android 8.0 эмулятор также отображает точку.

Вот как я сейчас делаю.Но setShowBadge (false) не работает

EDIT1:

        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        NotificationChannel tmpC = new NotificationChannel(id, "basic", NotificationManager.IMPORTANCE_MIN);
        tmpC.setShowBadge(false);

        manager.createNotificationChannel(tmpC);

        Notification notification = new NotificationCompat.Builder(this, id)
                .setChannelId(id)
                .setAutoCancel(true)
                .build();

        startForeground(getPackageName().hashCode(), notification);

1 Ответ

0 голосов
/ 01 февраля 2019

все, что вам нужно сделать, это вызвать setShowBadge(false) для вашего NotificationChannel объекта.

NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

// Create notification channel.
NotificationChannel channel = new NotificationChannel({channel_id}, {name}, {importance});
mChannel.setShowBadge(false); // Disable badges for this notification channel.
mNotificationManager.createNotificationChannel(mChannel);

// Create notification and use channel
Notification notification = new NotificationCompat.Builder(context, {channel_id})
         ...
         .build();

// notify
mNotificationManager.notify({notification_id}, notification)

Оформить Изменить значок уведомления .

...