From b6f95612ff7c8227c8a7a1fbba68104a8cd42fe6 Mon Sep 17 00:00:00 2001 From: kavikhalique Date: Fri, 6 Dec 2024 17:06:56 +0530 Subject: [PATCH] Modified startForeground() method call to adapt for android 14+ Signed-off-by: kavikhalique --- .../java/app/organicmaps/location/TrackRecordingService.java | 4 +++- .../main/java/app/organicmaps/routing/NavigationService.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/app/organicmaps/location/TrackRecordingService.java b/android/app/src/main/java/app/organicmaps/location/TrackRecordingService.java index b91adc936a..189b4bb5c5 100644 --- a/android/app/src/main/java/app/organicmaps/location/TrackRecordingService.java +++ b/android/app/src/main/java/app/organicmaps/location/TrackRecordingService.java @@ -6,6 +6,7 @@ import android.app.PendingIntent; import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.location.Location; import android.os.Build; import android.os.IBinder; @@ -17,6 +18,7 @@ import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationChannelCompat; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; +import androidx.core.app.ServiceCompat; import androidx.core.content.ContextCompat; import app.organicmaps.MwmActivity; import app.organicmaps.MwmApplication; @@ -163,7 +165,7 @@ public class TrackRecordingService extends Service implements LocationListener { try { - startForeground(TrackRecordingService.TRACK_REC_NOTIFICATION_ID, getNotificationBuilder(this).build()); + ServiceCompat.startForeground(this, TrackRecordingService.TRACK_REC_NOTIFICATION_ID, getNotificationBuilder(this).build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION); } catch (ForegroundServiceStartNotAllowedException e) { Logger.e(TAG, "Oops! ForegroundService is not allowed", e); diff --git a/android/app/src/main/java/app/organicmaps/routing/NavigationService.java b/android/app/src/main/java/app/organicmaps/routing/NavigationService.java index 8e492dbbde..985b089983 100644 --- a/android/app/src/main/java/app/organicmaps/routing/NavigationService.java +++ b/android/app/src/main/java/app/organicmaps/routing/NavigationService.java @@ -13,6 +13,7 @@ import android.app.PendingIntent; import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.location.Location; @@ -27,6 +28,7 @@ import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationChannelCompat; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; +import androidx.core.app.ServiceCompat; import androidx.core.content.ContextCompat; import app.organicmaps.Framework; @@ -228,7 +230,7 @@ public class NavigationService extends Service implements LocationListener { try { - startForeground(NavigationService.NOTIFICATION_ID, getNotificationBuilder(this).build()); + ServiceCompat.startForeground(this, NavigationService.NOTIFICATION_ID, getNotificationBuilder(this).build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION); } catch (ForegroundServiceStartNotAllowedException e) { Logger.e(TAG, "Oops! ForegroundService is not allowed", e); -- 2.45.3