add number of notifications to badge

This commit is contained in:
yenda 2020-06-15 16:27:28 +02:00
parent 51198f5b69
commit 9abf9d3891
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
2 changed files with 8 additions and 3 deletions

View File

@ -32,9 +32,11 @@ public class ForegroundService extends Service {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager =
context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(new NotificationChannel(CHANNEL_ID,
"Status Service",
NotificationManager.IMPORTANCE_HIGH));
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
"Status Service",
NotificationManager.IMPORTANCE_HIGH);
channel.setShowBadge(false);
notificationManager.createNotificationChannel(channel);
}
Class intentClass;
String packageName = context.getPackageName();
@ -63,6 +65,7 @@ public class ForegroundService extends Service {
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setContentIntent(pendingIntent)
.setNumber(0)
.addAction(R.drawable.ic_stat_notify_status, "STOP", stopPendingIntent)
.build();
// the id of the foreground notification MUST NOT be 0

View File

@ -166,6 +166,7 @@ public class NewMessageSignalHandler {
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();
channel.setSound(soundUri, audioAttributes);
channel.setShowBadge(true);
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
@ -205,6 +206,7 @@ public class NewMessageSignalHandler {
.setGroupSummary(true)
.setContentIntent(createOnTapIntent(context, notificationId, chat.getId()))
.setDeleteIntent(createOnDismissedIntent(context, notificationId, chat.getId()))
.setNumber(messages.size())
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= 21) {
builder.setVibrate(new long[0]);