diff --git a/android/src/main/kotlin/com/pravera/flutter_foreground_task/service/ForegroundServiceManager.kt b/android/src/main/kotlin/com/pravera/flutter_foreground_task/service/ForegroundServiceManager.kt index 18ad0df..70cb0a2 100644 --- a/android/src/main/kotlin/com/pravera/flutter_foreground_task/service/ForegroundServiceManager.kt +++ b/android/src/main/kotlin/com/pravera/flutter_foreground_task/service/ForegroundServiceManager.kt @@ -60,7 +60,10 @@ class ForegroundServiceManager { ForegroundTaskOptions.updateData(context, argsMap) ForegroundTaskData.updateData(context, argsMap) NotificationContent.updateData(context, argsMap) - ContextCompat.startForegroundService(context, nIntent) + // Use startService instead of startForegroundService because the service + // is already running in the foreground and we only need to deliver the + // update command. This avoids the startForeground() contract requirement. + context.startService(nIntent) } /** Stop the foreground service. */ @@ -76,7 +79,10 @@ class ForegroundServiceManager { ForegroundTaskOptions.clearData(context) ForegroundTaskData.clearData(context) NotificationContent.clearData(context) - ContextCompat.startForegroundService(context, nIntent) + // Use startService instead of startForegroundService because the service + // is already running in the foreground and we only need to deliver the + // stop command. This avoids the startForeground() contract requirement. + context.startService(nIntent) } /** Send data to TaskHandler. */