From 9b2f3069ebc3bb0664b43ac3fc764b7ae533d472 Mon Sep 17 00:00:00 2001 From: melad Date: Sun, 10 Mar 2024 15:50:11 +0200 Subject: [PATCH] fix android.app.InvalidForegroundServiceTypeException in android 14 --- id/src/main/AndroidManifest.xml | 7 +++++++ .../sync/events/down/EventDownSyncResetService.kt | 8 +++++++- .../java/com/simprints/core/workers/SimCoroutineWorker.kt | 7 ++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/id/src/main/AndroidManifest.xml b/id/src/main/AndroidManifest.xml index 08b9ae3513..86a11c38ab 100644 --- a/id/src/main/AndroidManifest.xml +++ b/id/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ + @@ -22,8 +23,14 @@ + + = Q then use FOREGROUND_SERVICE_TYPE_DATA_SYNC + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground(1, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC) + } else { + startForeground(1, notification) + } } } diff --git a/infra/core/src/main/java/com/simprints/core/workers/SimCoroutineWorker.kt b/infra/core/src/main/java/com/simprints/core/workers/SimCoroutineWorker.kt index 3268b1c408..78b6d51256 100644 --- a/infra/core/src/main/java/com/simprints/core/workers/SimCoroutineWorker.kt +++ b/infra/core/src/main/java/com/simprints/core/workers/SimCoroutineWorker.kt @@ -5,6 +5,7 @@ import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context +import android.content.pm.ServiceInfo import android.os.Build import androidx.core.app.NotificationCompat import androidx.work.CoroutineWorker @@ -98,7 +99,11 @@ abstract class SimCoroutineWorker( } } .build() - return ForegroundInfo(WORKER_FOREGROUND_NOTIFICATION_ID, notification) + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + ForegroundInfo(WORKER_FOREGROUND_NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC) + } else { + ForegroundInfo(WORKER_FOREGROUND_NOTIFICATION_ID, notification) + } } protected fun crashlyticsLog(message: String) {