diff --git a/oeffi/AndroidManifest.xml b/oeffi/AndroidManifest.xml
index 4cb6a08..f425bd9 100644
--- a/oeffi/AndroidManifest.xml
+++ b/oeffi/AndroidManifest.xml
@@ -233,6 +233,10 @@
android:authorities="de.schildbach.oeffi.stations.favorites"
android:exported="false" />
+
+
diff --git a/oeffi/res/layout/station_widget_content.xml b/oeffi/res/layout/station_widget_content.xml
index 47b5948..2d58a8e 100644
--- a/oeffi/res/layout/station_widget_content.xml
+++ b/oeffi/res/layout/station_widget_content.xml
@@ -66,8 +66,8 @@
android:id="@+id/station_widget_message"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_marginLeft="12dp"
- android:layout_marginRight="12dp"
+ android:layout_marginLeft="24dp"
+ android:layout_marginRight="24dp"
android:gravity="center"
android:textColor="#fff"
android:textStyle="bold"
diff --git a/oeffi/res/values-de/strings.xml b/oeffi/res/values-de/strings.xml
index 55aea9f..7dc1164 100644
--- a/oeffi/res/values-de/strings.xml
+++ b/oeffi/res/values-de/strings.xml
@@ -155,6 +155,7 @@
Abfahrtszeiten von nahegelegener favorisierter Haltestelle
+ Standortermittlung im Hintergrund ist nötig, um Haltestellen in deiner Nähe zu finden.\n\nTapp um die Erlaubnis zu geben.
Keine Haltestellen favorisiert.
Lade Abfahrtszeiten…
Keine Abfahrten.
diff --git a/oeffi/res/values/strings.xml b/oeffi/res/values/strings.xml
index f5b535a..bf96d6a 100644
--- a/oeffi/res/values/strings.xml
+++ b/oeffi/res/values/strings.xml
@@ -156,6 +156,7 @@
Departure times of nearest favorite station
+ Background Location Permission is needed for locating stations close to you.\n\nTap to grant permission.
No station favorites defined.
Loading departures…
No departures.
diff --git a/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java b/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java
index 7aba73a..9863562 100644
--- a/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java
+++ b/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java
@@ -136,9 +136,11 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
views = new RemoteViews(getPackageName(), R.layout.station_widget_content);
- if (ContextCompat.checkSelfPermission(this,
- Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
- widgetsMessage(appWidgetIds, getString(R.string.acquire_location_no_permission));
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED ||
+ ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+ final PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this,
+ NearestFavoriteStationsWidgetPermissionActivity.class), 0);
+ widgetsMessage(appWidgetIds, getString(R.string.nearest_favorite_station_widget_no_location_permission), intent);
log.info("No location permission");
return;
}
@@ -155,7 +157,7 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
criteria.setPowerRequirement(Criteria.POWER_LOW);
provider = locationManager.getBestProvider(criteria, true);
if (provider == null || LocationManager.PASSIVE_PROVIDER.equals(provider)) {
- widgetsMessage(appWidgetIds, getString(R.string.acquire_location_no_provider));
+ widgetsMessage(appWidgetIds, getString(R.string.acquire_location_no_provider), null);
log.info("No location provider found");
return;
}
@@ -193,14 +195,15 @@ public class NearestFavoriteStationWidgetService extends JobIntentService {
}
}
- private void widgetsMessage(final int[] appWidgetIds, final String message) {
+ private void widgetsMessage(final int[] appWidgetIds, final String message, final PendingIntent intent) {
setMessage(message);
views.setTextViewText(R.id.station_widget_distance, null);
views.setTextViewText(R.id.station_widget_lastupdated, null);
for (final int appWidgetId : appWidgetIds) {
views.setTextViewText(R.id.station_widget_header,
getString(R.string.nearest_favorite_station_widget_label));
- views.setOnClickPendingIntent(R.id.station_widget_content, clickIntent(appWidgetId));
+ views.setOnClickPendingIntent(R.id.station_widget_content,
+ intent != null ? intent : clickIntent(appWidgetId));
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
diff --git a/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationsWidgetPermissionActivity.java b/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationsWidgetPermissionActivity.java
new file mode 100644
index 0000000..0f9e752
--- /dev/null
+++ b/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationsWidgetPermissionActivity.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package de.schildbach.oeffi.stations;
+
+import android.Manifest;
+import android.app.Activity;
+import android.os.Bundle;
+import androidx.core.app.ActivityCompat;
+
+public class NearestFavoriteStationsWidgetPermissionActivity extends Activity {
+ @Override
+ protected void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION,
+ Manifest.permission.ACCESS_BACKGROUND_LOCATION }, 0);
+ }
+
+ @Override
+ public void onRequestPermissionsResult(final int requestCode, final String[] permissions,
+ final int[] grantResults) {
+ FavoriteUtils.notifyFavoritesChanged(this);
+ finish();
+ }
+}