after switching from forced foreground to foreground notification needs update

This commit is contained in:
Daniel Gultsch 2019-02-16 11:58:16 +01:00
parent 905d2ab432
commit 3fabb52293
2 changed files with 10 additions and 3 deletions

View file

@ -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); final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
try { try {
notificationManager.notify(id, notification); notificationManager.notify(id, notification);

View file

@ -4,6 +4,7 @@ import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
@ -1151,13 +1152,19 @@ public class XmppConnectionService extends Service {
private void toggleForegroundService(boolean force) { private void toggleForegroundService(boolean force) {
final boolean status; final boolean status;
if (force || mForceDuringOnCreate.get() || mForceForegroundService.get() || (Compatibility.keepForegroundService(this) && hasEnabledAccounts())) { 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; status = true;
} else { } else {
stopForeground(true); stopForeground(true);
status = false; 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")); Log.d(Config.LOGTAG,"ForegroundService: "+(status?"on":"off"));
} }