diff --git a/oeffi/AndroidManifest.xml b/oeffi/AndroidManifest.xml
index 5fc83a1..ff4f40a 100644
--- a/oeffi/AndroidManifest.xml
+++ b/oeffi/AndroidManifest.xml
@@ -33,6 +33,7 @@
+
+
+
diff --git a/oeffi/res/values-de/strings.xml b/oeffi/res/values-de/strings.xml
index 97e4145..8d327fd 100644
--- a/oeffi/res/values-de/strings.xml
+++ b/oeffi/res/values-de/strings.xml
@@ -334,6 +334,7 @@
Google Play
Herunterladen
Schließen
+ App-Widget-Aktivität
Fernverkehr
diff --git a/oeffi/res/values/strings.xml b/oeffi/res/values/strings.xml
index 1a02dd8..6828ab1 100644
--- a/oeffi/res/values/strings.xml
+++ b/oeffi/res/values/strings.xml
@@ -335,6 +335,7 @@
Google Play
Download
Dismiss
+ App-widget activity
Highspeed
diff --git a/oeffi/src/de/schildbach/oeffi/Application.java b/oeffi/src/de/schildbach/oeffi/Application.java
index 5c2c644..b98192c 100644
--- a/oeffi/src/de/schildbach/oeffi/Application.java
+++ b/oeffi/src/de/schildbach/oeffi/Application.java
@@ -30,13 +30,18 @@ import com.google.common.base.Stopwatch;
import de.schildbach.oeffi.directions.QueryHistoryProvider;
import de.schildbach.oeffi.stations.FavoriteStationsProvider;
+import de.schildbach.oeffi.stations.NearestFavoriteStationWidgetService;
import de.schildbach.oeffi.util.Downloader;
import de.schildbach.oeffi.util.ErrorReporter;
import de.schildbach.pte.NetworkId;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.Build;
import android.preference.PreferenceManager;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
@@ -147,6 +152,8 @@ public class Application extends android.app.Application {
QueryHistoryProvider.migrateQueryHistory(this, VAGFR, NetworkId.NVBW);
log.info("Migrations took {}", watch);
+
+ initNotificationManager();
}
private void initLogging() {
@@ -202,6 +209,20 @@ public class Application extends android.app.Application {
config.setUserAgentValue(getPackageName());
}
+ private void initNotificationManager() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ final Stopwatch watch = Stopwatch.createStarted();
+ final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+
+ final NotificationChannel appwidget = new NotificationChannel(
+ NearestFavoriteStationWidgetService.NOTIFICATION_CHANNEL_ID_APPWIDGET,
+ getString(R.string.notification_channel_appwidget_name), NotificationManager.IMPORTANCE_LOW);
+ nm.createNotificationChannel(appwidget);
+
+ log.info("created notification channels, took {}", watch);
+ }
+ }
+
private void migrateSelectedNetwork(final String fromName, final NetworkId to) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
diff --git a/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java b/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java
index 27c7885..fa42d33 100644
--- a/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java
+++ b/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java
@@ -62,6 +62,7 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
@@ -70,6 +71,7 @@ import android.text.format.DateFormat;
import android.view.View;
import android.widget.RemoteViews;
import androidx.core.app.JobIntentService;
+import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
public class NearestFavoriteStationWidgetService extends JobIntentService {
@@ -80,6 +82,8 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
private Handler backgroundHandler;
private static final int JOB_ID = 1;
+ public static final String NOTIFICATION_CHANNEL_ID_APPWIDGET = "appwidget";
+ private static final int NOTIFICATION_ID_APPWIDGET_UPDATE = 1;
private static final Logger log = LoggerFactory.getLogger(NearestFavoriteStationWidgetService.class);
@@ -110,6 +114,22 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
@Override
protected void onHandleWork(final Intent intent) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ final NotificationCompat.Builder notification = new NotificationCompat.Builder(this,
+ NOTIFICATION_CHANNEL_ID_APPWIDGET);
+ notification.setSmallIcon(R.drawable.ic_stat_notify_sync_24dp);
+ notification.setWhen(System.currentTimeMillis());
+ notification.setOngoing(true);
+ startForeground(NOTIFICATION_ID_APPWIDGET_UPDATE, notification.build());
+ }
+
+ handleIntent();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ stopForeground(true);
+ }
+
+ private void handleIntent() {
final ComponentName providerName = new ComponentName(this, NearestFavoriteStationWidgetProvider.class);
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);