From 3fabb5229388054892abb43ab266a3bda2383331 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 16 Feb 2019 11:58:16 +0100 Subject: [PATCH] after switching from forced foreground to foreground notification needs update --- .../conversations/services/NotificationService.java | 2 +- .../conversations/services/XmppConnectionService.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 1e7f03391..06ed560f3 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -1014,7 +1014,7 @@ public class NotificationService { } } - private void notify(int id, Notification notification) { + public void notify(int id, Notification notification) { final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService); try { notificationManager.notify(id, notification); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 1622c3899..fa3e524a5 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -4,6 +4,7 @@ import android.Manifest; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.AlarmManager; +import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; @@ -1151,13 +1152,19 @@ public class XmppConnectionService extends Service { private void toggleForegroundService(boolean force) { final boolean status; if (force || mForceDuringOnCreate.get() || mForceForegroundService.get() || (Compatibility.keepForegroundService(this) && hasEnabledAccounts())) { - startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification()); + final Notification notification = this.mNotificationService.createForegroundNotification(); + startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, notification); + if (!mForceForegroundService.get()) { + mNotificationService.notify(NotificationService.FOREGROUND_NOTIFICATION_ID, notification); + } status = true; } else { stopForeground(true); status = false; } - mNotificationService.dismissForcedForegroundNotification(); //if the channel was changed the previous call might fail + if (!mForceForegroundService.get()) { + mNotificationService.dismissForcedForegroundNotification(); //if the channel was changed the previous call might fail + } Log.d(Config.LOGTAG,"ForegroundService: "+(status?"on":"off")); }