From a2bd7b5c7cacd511fe3bbbe1dc9508a138658a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hur=C3=BDn?= Date: Sat, 21 Nov 2020 11:04:35 +0100 Subject: [PATCH] #155 - set constant for notification id to avoid multiple notifications --- .../yourlocalweather/service/SensorLocationUpdateService.java | 2 +- .../org/thosp/yourlocalweather/utils/NotificationUtils.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thosp/yourlocalweather/service/SensorLocationUpdateService.java b/app/src/main/java/org/thosp/yourlocalweather/service/SensorLocationUpdateService.java index b870d380c..53705bb04 100644 --- a/app/src/main/java/org/thosp/yourlocalweather/service/SensorLocationUpdateService.java +++ b/app/src/main/java/org/thosp/yourlocalweather/service/SensorLocationUpdateService.java @@ -142,7 +142,7 @@ private void registerSensorListener() { return; } - startForeground(android.os.Process.myPid(), notification); + startForeground(NotificationUtils.NOTIFICATION_ID, notification); sensorResolutionMultiplayer = 1 / senAccelerometer.getResolution(); int maxDelay = 10000; diff --git a/app/src/main/java/org/thosp/yourlocalweather/utils/NotificationUtils.java b/app/src/main/java/org/thosp/yourlocalweather/utils/NotificationUtils.java index 17f3fee53..d555b16c8 100644 --- a/app/src/main/java/org/thosp/yourlocalweather/utils/NotificationUtils.java +++ b/app/src/main/java/org/thosp/yourlocalweather/utils/NotificationUtils.java @@ -29,6 +29,8 @@ public class NotificationUtils { private static final String TAG = "NotificationUtils"; + public static final int NOTIFICATION_ID = 2109876543; + public static void weatherNotification(Context context, Long locationId) { /*String updateAutoPeriodStr = AppPreference.getLocationAutoUpdatePeriod(context); boolean updateBySensor = "0".equals(updateAutoPeriodStr); @@ -136,7 +138,7 @@ public static Notification getNotification(Context context, Location location, C public static void showNotification(Context context, Notification notification) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.notify(android.os.Process.myPid(), notification); + notificationManager.notify(NOTIFICATION_ID, notification); } private static Notification regularNotification(Context context,