Open wagner1343 opened 1 month ago
To view this pull requests documentation preview, visit the following URL:
docs.page/fluttercommunity/flutter_workmanager~573
Documentation is deployed and generated using docs.page.
@ened I Kindly ask for your input on this.
This pull request introduces foreground service support on Android devices as per Android workmanager docs Support for long-running workers.
Foreground service support:
createForegroundInfo
andcreateNotificationChannel
inBackgroundWorker.kt
to handle the creation of foreground notifications and channels.SetForeground
data class andparseSetForegroundCall
method inExtractor.kt
to parse method calls related to setting foreground options. [1] [2]setForeground
method andSetForegroundOptions
class inworkmanager.dart
to set foreground options from Dart code. [1] [2]Code refactoring and improvements:
onMethodCall
method inBackgroundWorker.kt
to handle the newSET_FOREGROUND
method call.BackgroundWorker.kt
andExtractor.kt
. [1] [2]These changes allows tasks to run as foreground services.
This PR addresses issue https://github.com/fluttercommunity/flutter_workmanager/issues/236, but goes against the recomendation on https://github.com/fluttercommunity/flutter_workmanager/pull/511 of using
Workmanager.registerProcessingTask
to implement long-running wokers on android. Since the implementation of long-running workers on Android tightly depends on specific requirements such as handling notifications and activating a foreground service on the run, a decision was made to create a dedicated API which laverages ListenableWorker.serForegroundAsync and minimally handles notification management in order to implement long-running workers while following android guidelines.