add number of notifications to badge
This commit is contained in:
parent
51198f5b69
commit
9abf9d3891
|
@ -32,9 +32,11 @@ public class ForegroundService extends Service {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
NotificationManager notificationManager =
|
NotificationManager notificationManager =
|
||||||
context.getSystemService(NotificationManager.class);
|
context.getSystemService(NotificationManager.class);
|
||||||
notificationManager.createNotificationChannel(new NotificationChannel(CHANNEL_ID,
|
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
|
||||||
"Status Service",
|
"Status Service",
|
||||||
NotificationManager.IMPORTANCE_HIGH));
|
NotificationManager.IMPORTANCE_HIGH);
|
||||||
|
channel.setShowBadge(false);
|
||||||
|
notificationManager.createNotificationChannel(channel);
|
||||||
}
|
}
|
||||||
Class intentClass;
|
Class intentClass;
|
||||||
String packageName = context.getPackageName();
|
String packageName = context.getPackageName();
|
||||||
|
@ -63,6 +65,7 @@ public class ForegroundService extends Service {
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
|
.setNumber(0)
|
||||||
.addAction(R.drawable.ic_stat_notify_status, "STOP", stopPendingIntent)
|
.addAction(R.drawable.ic_stat_notify_status, "STOP", stopPendingIntent)
|
||||||
.build();
|
.build();
|
||||||
// the id of the foreground notification MUST NOT be 0
|
// the id of the foreground notification MUST NOT be 0
|
||||||
|
|
|
@ -166,6 +166,7 @@ public class NewMessageSignalHandler {
|
||||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
||||||
.build();
|
.build();
|
||||||
channel.setSound(soundUri, audioAttributes);
|
channel.setSound(soundUri, audioAttributes);
|
||||||
|
channel.setShowBadge(true);
|
||||||
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
|
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
|
||||||
notificationManager.createNotificationChannel(channel);
|
notificationManager.createNotificationChannel(channel);
|
||||||
}
|
}
|
||||||
|
@ -205,6 +206,7 @@ public class NewMessageSignalHandler {
|
||||||
.setGroupSummary(true)
|
.setGroupSummary(true)
|
||||||
.setContentIntent(createOnTapIntent(context, notificationId, chat.getId()))
|
.setContentIntent(createOnTapIntent(context, notificationId, chat.getId()))
|
||||||
.setDeleteIntent(createOnDismissedIntent(context, notificationId, chat.getId()))
|
.setDeleteIntent(createOnDismissedIntent(context, notificationId, chat.getId()))
|
||||||
|
.setNumber(messages.size())
|
||||||
.setAutoCancel(true);
|
.setAutoCancel(true);
|
||||||
if (Build.VERSION.SDK_INT >= 21) {
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
builder.setVibrate(new long[0]);
|
builder.setVibrate(new long[0]);
|
||||||
|
|
Loading…
Reference in New Issue