Reputation: 37
On Oreo (API 18), I don't want to use notification dot.
But it show notification dot default.
For instance, YouTube push notification but don't use notification dot.
I'am using NotificationChannel And I tried using
NotificationChannel.setShowBadge(false)
But it didn't work.
How can I do this?
youtube - has no notification dot
myApp - has notification dot
Upvotes: 1
Views: 2207
Reputation: 4835
When you create your notification under Oreo you must create a channel instance and assign it to the notification. You use setShowBadge
on your instance.
Below is my code which correctly removes the badge.
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
String CHANNEL_ID = "my_channel";
CharSequence name = context.getString(R.string.channel_name);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_LOW);
channel.setShowBadge(false);
notificationManager.createNotificationChannel(channel);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context, CHANNEL_ID).setSmallIcon(iconID)
.setContentTitle(task.taskTitle)
.setContentText(task.taskNote).setOngoing(true).setWhen(0)
.setChannelId(CHANNEL_ID)
.setSound(null)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
notificationManager.notify(task.driveId, NOTIFICATION_ID, builder.build());
Upvotes: 5