diff --git a/OsmAnd/src/net/osmand/plus/NavigationService.java b/OsmAnd/src/net/osmand/plus/NavigationService.java index 39d29fd688..7a2959a2a3 100644 --- a/OsmAnd/src/net/osmand/plus/NavigationService.java +++ b/OsmAnd/src/net/osmand/plus/NavigationService.java @@ -191,9 +191,16 @@ public class NavigationService extends Service implements LocationListener { // registering icon at top level // Leave icon visible even for navigation for proper display Notification notification = app.getNotificationHelper().buildTopNotification(); - startForeground(OsmandNotification.TOP_NOTIFICATION_SERVICE_ID, notification); - app.getNotificationHelper().refreshNotifications(); - return START_REDELIVER_INTENT; + if (notification != null) { + startForeground(OsmandNotification.TOP_NOTIFICATION_SERVICE_ID, notification); + app.getNotificationHelper().refreshNotifications(); + return START_REDELIVER_INTENT; + } else { + notification = app.getNotificationHelper().buildErrorNotification(); + startForeground(OsmandNotification.TOP_NOTIFICATION_SERVICE_ID, notification); + stopSelf(); + return START_NOT_STICKY; + } } diff --git a/OsmAnd/src/net/osmand/plus/NotificationHelper.java b/OsmAnd/src/net/osmand/plus/NotificationHelper.java index df81b6bce8..931107e4b0 100644 --- a/OsmAnd/src/net/osmand/plus/NotificationHelper.java +++ b/OsmAnd/src/net/osmand/plus/NotificationHelper.java @@ -46,7 +46,6 @@ public class NotificationHelper { all.add(downloadNotification); } - @NonNull public Notification buildTopNotification() { OsmandNotification notification = acquireTopNotification(); if (notification != null) { @@ -56,10 +55,10 @@ public class NotificationHelper { if (notificationBuilder != null) { return notificationBuilder.build(); } else { - return buildErrorNotification(); + return null; } } else { - return buildErrorNotification(); + return null; } } @@ -68,7 +67,7 @@ public class NotificationHelper { return downloadNotification.buildNotification(false).build(); } - private Notification buildErrorNotification() { + public Notification buildErrorNotification() { removeNotification(errorNotification.getType()); setTopNotification(errorNotification); return errorNotification.buildNotification(false).build();