From bdf0b0e07d526dd6f9e3392aec012b0bbf6d017d Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 30 Jun 2019 15:36:30 +0200 Subject: [PATCH 1/4] Make updateNotification public --- .../persistentNotification/PersistentNotificationPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java index c302f71b38..24ce87bc23 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java @@ -122,7 +122,7 @@ public class PersistentNotificationPlugin extends PluginBase { } @Nonnull - Notification updateNotification() { + public Notification updateNotification() { String line1 = null; String line2 = null; String line3 = null; From d42794137f2c890e5f8f5c5110a6a2638a2648cd Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 30 Jun 2019 15:38:04 +0200 Subject: [PATCH 2/4] call startForeground() --- .../nightscout/androidaps/services/AlarmSoundService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.java b/app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.java index 4917789db1..e8639d8744 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps.services; +import android.app.Notification; import android.app.Service; import android.content.Context; import android.content.Intent; @@ -16,6 +17,7 @@ import java.io.IOException; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin; public class AlarmSoundService extends Service { private static Logger log = LoggerFactory.getLogger(L.CORE); @@ -28,8 +30,7 @@ public class AlarmSoundService extends Service { @Override public IBinder onBind(Intent intent) { - // TODO: Return the communication channel to the service. - throw new UnsupportedOperationException("Not yet implemented"); + return null; } @Override @@ -40,6 +41,8 @@ public class AlarmSoundService extends Service { } public int onStartCommand(Intent intent, int flags, int startId) { + Notification notification = PersistentNotificationPlugin.getPlugin().updateNotification(); + startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, notification); if (player != null && player.isPlaying()) player.stop(); if (L.isEnabled(L.CORE)) From 1282e3ed9e13ec2ac163c490d494cf09045747e1 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 30 Jun 2019 15:57:04 +0200 Subject: [PATCH 3/4] Get Singleton Notification --- .../PersistentNotificationPlugin.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java index 24ce87bc23..9dcb800033 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java @@ -52,6 +52,7 @@ import info.nightscout.androidaps.utils.DecimalFormatter; public class PersistentNotificationPlugin extends PluginBase { private static PersistentNotificationPlugin plugin; + private Notification notification; public static PersistentNotificationPlugin getPlugin() { if (plugin == null) plugin = new PersistentNotificationPlugin(MainApp.instance()); @@ -122,7 +123,7 @@ public class PersistentNotificationPlugin extends PluginBase { } @Nonnull - public Notification updateNotification() { + Notification updateNotification() { String line1 = null; String line2 = null; String line3 = null; @@ -250,6 +251,7 @@ public class PersistentNotificationPlugin extends PluginBase { android.app.Notification notification = builder.build(); mNotificationManager.notify(ONGOING_NOTIFICATION_ID, notification); + this.notification = notification; return notification; } @@ -269,6 +271,17 @@ public class PersistentNotificationPlugin extends PluginBase { return deltastring; } + /*** + * returns the current ongoing notification. + * + * If it does not exist, return a dummy notification. This should only happen if onStart() wasn't called. + */ + + public Notification getLastNotification() { + if (notification != null) return notification; + else return new Notification(); + } + @Subscribe public void onStatusEvent(final EventPreferenceChange ev) { From b274647f68098a2ae8ed4903b12e319d0efe26b3 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sun, 30 Jun 2019 15:58:04 +0200 Subject: [PATCH 4/4] get last notification --- .../info/nightscout/androidaps/services/AlarmSoundService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.java b/app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.java index e8639d8744..a62f2c6fb7 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/AlarmSoundService.java @@ -41,7 +41,7 @@ public class AlarmSoundService extends Service { } public int onStartCommand(Intent intent, int flags, int startId) { - Notification notification = PersistentNotificationPlugin.getPlugin().updateNotification(); + Notification notification = PersistentNotificationPlugin.getPlugin().getLastNotification(); startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, notification); if (player != null && player.isPlaying()) player.stop();