Merge pull request #1853 from MilosKozak/sdk28-fix-servicecrash-1
Sdk28 fix servicecrash 1
This commit is contained in:
commit
9a8bcdc67e
2 changed files with 18 additions and 2 deletions
|
@ -52,6 +52,7 @@ import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||||
public class PersistentNotificationPlugin extends PluginBase {
|
public class PersistentNotificationPlugin extends PluginBase {
|
||||||
|
|
||||||
private static PersistentNotificationPlugin plugin;
|
private static PersistentNotificationPlugin plugin;
|
||||||
|
private Notification notification;
|
||||||
|
|
||||||
public static PersistentNotificationPlugin getPlugin() {
|
public static PersistentNotificationPlugin getPlugin() {
|
||||||
if (plugin == null) plugin = new PersistentNotificationPlugin(MainApp.instance());
|
if (plugin == null) plugin = new PersistentNotificationPlugin(MainApp.instance());
|
||||||
|
@ -250,6 +251,7 @@ public class PersistentNotificationPlugin extends PluginBase {
|
||||||
|
|
||||||
android.app.Notification notification = builder.build();
|
android.app.Notification notification = builder.build();
|
||||||
mNotificationManager.notify(ONGOING_NOTIFICATION_ID, notification);
|
mNotificationManager.notify(ONGOING_NOTIFICATION_ID, notification);
|
||||||
|
this.notification = notification;
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,6 +271,17 @@ public class PersistentNotificationPlugin extends PluginBase {
|
||||||
return deltastring;
|
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
|
@Subscribe
|
||||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.services;
|
package info.nightscout.androidaps.services;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -16,6 +17,7 @@ import java.io.IOException;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin;
|
||||||
|
|
||||||
public class AlarmSoundService extends Service {
|
public class AlarmSoundService extends Service {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
||||||
|
@ -28,8 +30,7 @@ public class AlarmSoundService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
// TODO: Return the communication channel to the service.
|
return null;
|
||||||
throw new UnsupportedOperationException("Not yet implemented");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,6 +41,8 @@ public class AlarmSoundService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
Notification notification = PersistentNotificationPlugin.getPlugin().getLastNotification();
|
||||||
|
startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, notification);
|
||||||
if (player != null && player.isPlaying())
|
if (player != null && player.isPlaying())
|
||||||
player.stop();
|
player.stop();
|
||||||
if (L.isEnabled(L.CORE))
|
if (L.isEnabled(L.CORE))
|
||||||
|
|
Loading…
Reference in a new issue