diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..d3c690d2 Binary files /dev/null and b/.DS_Store differ diff --git a/.github/workflows/pub.yml b/.github/workflows/pub.yml new file mode 100644 index 00000000..2aeebc1e --- /dev/null +++ b/.github/workflows/pub.yml @@ -0,0 +1,49 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Pub + +on: + push: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Prepare credentials + run: | + mkdir ~/.config/dart + echo ${{ secrets.PUB_CREDENTIAL }} | base64 --decode > ~/.config/dart/pub-credentials.json + - name: Setup git + run: | + git config --local user.email "mr.poetra22@gmail.com" + git config --local user.name "Eka Setiawan Saputra" + - name: Install Flutter + id: install + continue-on-error: true + uses: subosito/flutter-action@v1 + with: + channel: "stable" + - name: 'Get Dependencies' + run: flutter pub get + - name: 'Install melos' + run: dart pub global activate melos + - name: 'Update versions' + run: melos version --yes + + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GIT_PAT }} + branch: master + tags: true + + - name: 'Publish to pub.dev' + run: melos publish --no-dry-run -y diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 11b72fa3..00000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,43 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Pub Publish - -on: - push: - tags: - - v0.* - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Set env - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV - - - uses: actions/checkout@v2 - - name: Install Java - uses: actions/setup-java@v1 - with: - java-version: "12.x" - - - name: Install Flutter - uses: subosito/flutter-action@v1 - with: - channel: "stable" - - - name: Flutter Pub Get - run: flutter pub get - - - name: Evaluate version - run: flutter pub run bin/update - - - name: Prepare pub credentials - run: | - mkdir -p $XDG_CONFIG_HOME/.config/dart - echo '${{ secrets.PUB_CREDENTIAL }}' > "$XDG_CONFIG_HOME/dart/pub-credentials.json" - - - name: Publish - run: flutter pub publish -f diff --git a/.gitignore b/.gitignore index 899ae641..014f0465 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,2 @@ -.DS_Store -.dart_tool/ - -.packages -.pub/ - -build/ -pubspec.lock -.idea/ +**/pubspec_overrides.yaml +.dart_tool/** \ No newline at end of file diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..d1c9e343 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +flutter_background_service \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..7529a37f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/melos_bootstrap.xml b/.idea/runConfigurations/melos_bootstrap.xml new file mode 100644 index 00000000..d5715306 --- /dev/null +++ b/.idea/runConfigurations/melos_bootstrap.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/.idea/runConfigurations/melos_clean.xml b/.idea/runConfigurations/melos_clean.xml new file mode 100644 index 00000000..f45d4362 --- /dev/null +++ b/.idea/runConfigurations/melos_clean.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/.idea/runConfigurations/melos_flutter_run_example.xml b/.idea/runConfigurations/melos_flutter_run_example.xml new file mode 100644 index 00000000..d408ded3 --- /dev/null +++ b/.idea/runConfigurations/melos_flutter_run_example.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/melos_flutter_test_flutter_background_service.xml b/.idea/runConfigurations/melos_flutter_test_flutter_background_service.xml new file mode 100644 index 00000000..c332a2fe --- /dev/null +++ b/.idea/runConfigurations/melos_flutter_test_flutter_background_service.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/melos_flutter_test_flutter_background_service_android.xml b/.idea/runConfigurations/melos_flutter_test_flutter_background_service_android.xml new file mode 100644 index 00000000..ef784c15 --- /dev/null +++ b/.idea/runConfigurations/melos_flutter_test_flutter_background_service_android.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/melos_flutter_test_flutter_background_service_ios.xml b/.idea/runConfigurations/melos_flutter_test_flutter_background_service_ios.xml new file mode 100644 index 00000000..bd5e27b4 --- /dev/null +++ b/.idea/runConfigurations/melos_flutter_test_flutter_background_service_ios.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/melos_flutter_test_flutter_background_service_platform_interface.xml b/.idea/runConfigurations/melos_flutter_test_flutter_background_service_platform_interface.xml new file mode 100644 index 00000000..66687e44 --- /dev/null +++ b/.idea/runConfigurations/melos_flutter_test_flutter_background_service_platform_interface.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/melos_run_postclean.xml b/.idea/runConfigurations/melos_run_postclean.xml new file mode 100644 index 00000000..c73b4a2e --- /dev/null +++ b/.idea/runConfigurations/melos_run_postclean.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..6c73580b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Flutter: Attach to Device", + "type": "dart", + "request": "attach" + }, + { + "name": "example", + "cwd": "packages/flutter_background_service/example", + "request": "launch", + "type": "dart" + }, + { + "name": "example (release)", + "cwd": "packages/flutter_background_service/example", + "request": "launch", + "type": "dart", + "flutterMode": "release" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 7a73a41b..7f69797d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,2 +1,3 @@ { + "dart.runPubGetOnPubspecChanges": false } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 44d76d7f..18732fb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,134 +1,1928 @@ -## 0.2.6 -* FIX: (Android) flutter initialization -## 0.2.5 -* FIX: (iOS) using other plugins -## 0.2.4 -* FIX: (Android) run service background when charger not connected and screen lock (#92) -## 0.2.3 -* ADDED: Using `BGTaskScheduler` on iOS 13. See readme for configuration. -## 0.2.2 -* ADDED: `autoStart` to `IosConfiguration` -## 0.2.1 -* UPDATE README -* UPDATE: Flutter Version Constraint -## 0.2.0+1 -* UPDATE README +# Change Log -## 0.2.0 -* [BREAKING]: FlutterBackgroundService.initialize renamed to FlutterBackgroundService.configure -* [BREAKING]: use FlutterBackgroundService.start to start or restart after you call stopService. -* [ADDED]: IOS Background fetch is now supported you have to enable background fetch from xcode. -## 0.1.7 +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. -* Fix : cannot start service on android 12 -* Fix : not started on boot completed -## 0.1.6 +## 2025-07-25 -* Android 12 Compatibility Changes -## 0.1.5 +### Changes -* Rollback foreground notification importance -## 0.1.4 +--- -* fixes UnsatisfiedLinkError when running as foreground service with autostart #32 -## 0.1.3 +Packages with breaking changes: -* Fix notification not showing on android 7 and prior (Issue #26) -## 0.1.2 + - There are no breaking changes in this release. -* Open app from notification (Issue #30) -## 0.1.1 +Packages with other changes: -* Fix #29 (DartVM not terminated when service stop) + - [`flutter_background_service_android` - `v6.3.1`](#flutter_background_service_android---v631) + - [`flutter_background_service` - `v5.1.1`](#flutter_background_service---v511) -## 0.1.0 +Packages with dependency updates only: -* Bump flutter 2 +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. -## 0.1.0-nullsafety.2 + - `flutter_background_service` - `v5.1.1` -* Fix #23 +--- -## 0.1.0-nullsafety.1 +#### `flutter_background_service_android` - `v6.3.1` -* Added isServiceRunning on iOS (issue #19) + - **FIX**(android): add namespace to support AGP 8.0+. ([76b0c396](https://github.com/ekasetiawans/flutter_background_service/commit/76b0c3960e2e65b5be8c60a2de0b7c0565691769)) + - **FIX**: manually disabling Alarms & reminders permission on Android 12 causes an exception when starting service on reboot. ([135fed1f](https://github.com/ekasetiawans/flutter_background_service/commit/135fed1f3a49b5c674718a112beb2ca71a19d1b0)) -## 0.1.0-nullsafety.0 -* Added support to nullsafety +## 2025-07-25 -## 0.0.1+18 +### Changes -* Added stopService Method(Currently Works on Android Only). +--- -## 0.0.1+17 +Packages with breaking changes: -* Add preference autoStart on Boot, default is true. + - There are no breaking changes in this release. -## 0.0.1+16 +Packages with other changes: -* Set Foreground Mode to false will remove notification. BugFix #4. + - [`flutter_background_service_android` - `v6.3.1`](#flutter_background_service_android---v631) + - [`flutter_background_service` - `v5.1.1`](#flutter_background_service---v511) -## 0.0.1+15 +Packages with dependency updates only: -* Add ability to change Background or Foreground mode (Android Only) +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. -## 0.0.1+14 + - `flutter_background_service` - `v5.1.1` -* Bugfix BootReceiver +--- -## 0.0.1+13 +#### `flutter_background_service_android` - `v6.3.1` -* Update example for iOS support. + - **FIX**(android): add namespace to support AGP 8.0+. ([76b0c396](https://github.com/ekasetiawans/flutter_background_service/commit/76b0c3960e2e65b5be8c60a2de0b7c0565691769)) + - **FIX**: manually disabling Alarms & reminders permission on Android 12 causes an exception when starting service on reboot. ([135fed1f](https://github.com/ekasetiawans/flutter_background_service/commit/135fed1f3a49b5c674718a112beb2ca71a19d1b0)) -## 0.0.1+12 -* Start service immediately after initialize +## 2024-12-21 -## 0.0.1+11 +### Changes -* iOS +--- -## 0.0.1+10 +Packages with breaking changes: -* bug fix + - There are no breaking changes in this release. -## 0.0.1+9 +Packages with other changes: -* bug fix + - [`flutter_background_service` - `v5.1.0`](#flutter_background_service---v510) + - [`flutter_background_service_android` - `v6.3.0`](#flutter_background_service_android---v630) -## 0.0.1+8 +--- -* bug fix +#### `flutter_background_service` - `v5.1.0` -## 0.0.1+7 + - **FEAT**: remove unused imports. ([d0bbb433](https://github.com/ekasetiawans/flutter_background_service/commit/d0bbb43312877af51b5403c6fc42dd9ec2a44789)) -* Add ability to send data from UI to Service +#### `flutter_background_service_android` - `v6.3.0` -## 0.0.1+6 + - **FEAT**: remove unused imports. ([d0bbb433](https://github.com/ekasetiawans/flutter_background_service/commit/d0bbb43312877af51b5403c6fc42dd9ec2a44789)) -* Improve stability -## 0.0.1+5 +## 2024-12-21 -* Add ability to send data from service to UI +### Changes -## 0.0.1+4 +--- -* Update README +Packages with breaking changes: -## 0.0.1+3 + - There are no breaking changes in this release. -* Add ability to change notification info (Android foreground service) +Packages with other changes: -## 0.0.1+2 + - [`flutter_background_service` - `v5.1.0`](#flutter_background_service---v510) + - [`flutter_background_service_android` - `v6.3.0`](#flutter_background_service_android---v630) -* Fix android missing plugin implementation +--- -## 0.0.1+1 +#### `flutter_background_service` - `v5.1.0` -* Fix android build + - **FEAT**: remove unused imports. ([d0bbb433](https://github.com/ekasetiawans/flutter_background_service/commit/d0bbb43312877af51b5403c6fc42dd9ec2a44789)) -## 0.0.1 +#### `flutter_background_service_android` - `v6.3.0` + + - **FEAT**: remove unused imports. ([d0bbb433](https://github.com/ekasetiawans/flutter_background_service/commit/d0bbb43312877af51b5403c6fc42dd9ec2a44789)) + + +## 2024-08-29 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v6.2.7`](#flutter_background_service_android---v627) + - [`flutter_background_service` - `v5.0.10`](#flutter_background_service---v5010) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v5.0.10` + +--- + +#### `flutter_background_service_android` - `v6.2.7` + + - **BUG**: service crash due to START_STICKY. ([a000a6ba](https://github.com/ekasetiawans/flutter_background_service/commit/a000a6bae974de543c9f37275e2aab177c197339)) + + +## 2024-08-25 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_platform_interface` - `v5.1.2`](#flutter_background_service_platform_interface---v512) + - [`flutter_background_service` - `v5.0.9`](#flutter_background_service---v509) + - [`flutter_background_service_android` - `v6.2.6`](#flutter_background_service_android---v626) + - [`flutter_background_service_ios` - `v5.0.3`](#flutter_background_service_ios---v503) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v5.0.9` + - `flutter_background_service_android` - `v6.2.6` + - `flutter_background_service_ios` - `v5.0.3` + +--- + +#### `flutter_background_service_platform_interface` - `v5.1.2` + + - **FIX**: fix lints. ([95186405](https://github.com/ekasetiawans/flutter_background_service/commit/95186405f2d60112ff83956bce345ebbbc332ad7)) + + +## 2024-08-25 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v5.0.8`](#flutter_background_service---v508) + - [`flutter_background_service_android` - `v6.2.5`](#flutter_background_service_android---v625) + +--- + +#### `flutter_background_service` - `v5.0.8` + + - **FIX**: lints. ([7b63fca4](https://github.com/ekasetiawans/flutter_background_service/commit/7b63fca4e97941b2891570bd80701c7bb98cda23)) + +#### `flutter_background_service_android` - `v6.2.5` + + - **FIX**: lints. ([7b63fca4](https://github.com/ekasetiawans/flutter_background_service/commit/7b63fca4e97941b2891570bd80701c7bb98cda23)) + + +## 2024-08-03 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v5.0.7`](#flutter_background_service---v507) + - [`flutter_background_service_android` - `v6.2.4`](#flutter_background_service_android---v624) + - [`flutter_background_service_platform_interface` - `v5.1.1`](#flutter_background_service_platform_interface---v511) + - [`flutter_background_service_ios` - `v5.0.2`](#flutter_background_service_ios---v502) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service_ios` - `v5.0.2` + +--- + +#### `flutter_background_service` - `v5.0.7` + + - **FIX**: fix crash on android 14 after starting foreground service. ([4bdc46d9](https://github.com/ekasetiawans/flutter_background_service/commit/4bdc46d951febafbcbb2b118324cddc2b30ad752)) + +#### `flutter_background_service_android` - `v6.2.4` + + - **FIX**: fix crash on android 14 after starting foreground service. ([4bdc46d9](https://github.com/ekasetiawans/flutter_background_service/commit/4bdc46d951febafbcbb2b118324cddc2b30ad752)) + +#### `flutter_background_service_platform_interface` - `v5.1.1` + + - **FIX**: fix crash on android 14 after starting foreground service. ([4bdc46d9](https://github.com/ekasetiawans/flutter_background_service/commit/4bdc46d951febafbcbb2b118324cddc2b30ad752)) + + +## 2024-06-18 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_platform_interface` - `v5.1.0`](#flutter_background_service_platform_interface---v510) + - [`flutter_background_service` - `v5.0.6`](#flutter_background_service---v506) + - [`flutter_background_service_android` - `v6.2.3`](#flutter_background_service_android---v623) + - [`flutter_background_service_ios` - `v5.0.1`](#flutter_background_service_ios---v501) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v5.0.6` + - `flutter_background_service_android` - `v6.2.3` + - `flutter_background_service_ios` - `v5.0.1` + +--- + +#### `flutter_background_service_platform_interface` - `v5.1.0` + + - **FEAT**: updated dependencies. ([e90ad787](https://github.com/ekasetiawans/flutter_background_service/commit/e90ad787b3a7b157aeeec3a45920839aafe2933d)) + + +## 2023-11-30 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v5.0.5`](#flutter_background_service---v505) + - [`flutter_background_service_android` - `v6.2.2`](#flutter_background_service_android---v622) + +--- + +#### `flutter_background_service` - `v5.0.5` + + - **FIX**: android build error. ([8102e015](https://github.com/ekasetiawans/flutter_background_service/commit/8102e01563b967cea588a09b8a9773fc56b0dd2c)) + +#### `flutter_background_service_android` - `v6.2.2` + + - **FIX**: android build error. ([8102e015](https://github.com/ekasetiawans/flutter_background_service/commit/8102e01563b967cea588a09b8a9773fc56b0dd2c)) + + +## 2023-11-18 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v6.2.1`](#flutter_background_service_android---v621) + - [`flutter_background_service` - `v5.0.4`](#flutter_background_service---v504) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v5.0.4` + +--- + +#### `flutter_background_service_android` - `v6.2.1` + + - **FIX**: checks methodChanel's nullabilty inside MainHandler.post. ([cd0d098f](https://github.com/ekasetiawans/flutter_background_service/commit/cd0d098f76fb9e211ab5db1a08f19cfd21827b30)) + - **FIX**: removes listener before turn methodChannel null. ([7909b51c](https://github.com/ekasetiawans/flutter_background_service/commit/7909b51cafbf6e79ad0f875e73889ad1b2b5fc34)) + + +## 2023-11-06 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v6.2.0`](#flutter_background_service_android---v620) + - [`flutter_background_service` - `v5.0.3`](#flutter_background_service---v503) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v5.0.3` + +--- + +#### `flutter_background_service_android` - `v6.2.0` + + - **FEAT**: throw an error if using FlutterBackgroundService class in worker isolate. ([9a5732ce](https://github.com/ekasetiawans/flutter_background_service/commit/9a5732cef65ce5b33e699569cd88c98521c002ac)) + + +## 2023-10-19 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v6.1.0`](#flutter_background_service_android---v610) + - [`flutter_background_service` - `v5.0.2`](#flutter_background_service---v502) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v5.0.2` + +--- + +#### `flutter_background_service_android` - `v6.1.0` + + - **FEAT**: throw an error if using FlutterBackgroundService class in worker isolate. ([d09843f8](https://github.com/ekasetiawans/flutter_background_service/commit/d09843f82a6d4a9ef19529ab27701ab68f68ee7c)) + + +## 2023-08-14 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v6.0.1`](#flutter_background_service_android---v601) + - [`flutter_background_service` - `v5.0.1`](#flutter_background_service---v501) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v5.0.1` + +--- + +#### `flutter_background_service_android` - `v6.0.1` + + - **FIX**: service do not connect to dart side after destroy by xiaomi boost memory. ([a04d3a75](https://github.com/ekasetiawans/flutter_background_service/commit/a04d3a75ca0a8e4683802b0a01e41b0dd50ba37b)) + + +## 2023-08-11 + +### Changes + +--- + +Packages with breaking changes: + + - [`flutter_background_service` - `v5.0.0`](#flutter_background_service---v500) + - [`flutter_background_service_android` - `v6.0.0`](#flutter_background_service_android---v600) + - [`flutter_background_service_ios` - `v5.0.0`](#flutter_background_service_ios---v500) + - [`flutter_background_service_platform_interface` - `v5.0.0`](#flutter_background_service_platform_interface---v500) + +Packages with other changes: + + - There are no other changes in this release. + +--- + +#### `flutter_background_service` - `v5.0.0` + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **REFACTOR**: fix sampe project dependency version. ([a83b9f62](https://github.com/ekasetiawans/flutter_background_service/commit/a83b9f62dd0d16f8bd23657ef1f36cb7d51fb0fa)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FIX**: added @pragma. ([0f90cc7d](https://github.com/ekasetiawans/flutter_background_service/commit/0f90cc7d6f1ae9b0e2ab6132151e27b88814afe1)) + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + - **FIX**: wrong dependency version. ([34e66e13](https://github.com/ekasetiawans/flutter_background_service/commit/34e66e13f04afe760d7b4087cc7052756dcb2a9c)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + - **FIX**: dependencies version. ([4e89b5e9](https://github.com/ekasetiawans/flutter_background_service/commit/4e89b5e9e5aa55074e1b10b41ea057c4b1b0bfcb)) + - **FEAT**: enhance notification icon readme. ([52e7e6ea](https://github.com/ekasetiawans/flutter_background_service/commit/52e7e6ea8bdff67924d93ce716b395bdbba2a48b)) + - **FEAT**: enhance notification icon readme. ([4d699fb0](https://github.com/ekasetiawans/flutter_background_service/commit/4d699fb03b83eae09bc3696f443a8e36092c8789)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + - **FEAT**: update dependencies. ([afc90fcc](https://github.com/ekasetiawans/flutter_background_service/commit/afc90fcc07b39954147dd24915258c96863e573e)) + - **FEAT**: managed with melos. ([2313273a](https://github.com/ekasetiawans/flutter_background_service/commit/2313273a3e728e37e2fb973ccc146841c8af48da)) + - **DOCS**: updated README.md. ([9345b16f](https://github.com/ekasetiawans/flutter_background_service/commit/9345b16f7c69e7acac1ea5d8a5985b97092a1220)) + - **DOCS**: updated README. ([f9e96ab4](https://github.com/ekasetiawans/flutter_background_service/commit/f9e96ab4978f348342703cf1de011bc59f6b9e4c)) + - **DOCS**: update README. ([5fc18ced](https://github.com/ekasetiawans/flutter_background_service/commit/5fc18ced43cc7fc1df3209eaa21ef9d424d41779)) + - **DOCS**: add documentation on configure method. ([b9612afe](https://github.com/ekasetiawans/flutter_background_service/commit/b9612afe593e766e740c69ee01a04b4f9d2ec83a)) + - **DOCS**: update FAQ. ([53215976](https://github.com/ekasetiawans/flutter_background_service/commit/532159768bc4a14701940c8166440bb1940aa1b5)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: updated README. ([2fc9ae66](https://github.com/ekasetiawans/flutter_background_service/commit/2fc9ae66f5538ab45f3690cdaee94f89b31f16e2)) + - **DOCS**: update example project for custom notification. ([d1e90d86](https://github.com/ekasetiawans/flutter_background_service/commit/d1e90d864d281747ab40170e22d91601b29927a6)) + - **DOCS**: update README. ([caf8125c](https://github.com/ekasetiawans/flutter_background_service/commit/caf8125cf557b009e06995fcc7ea8a006eba3dae)) + - **DOCS**: update README. ([88917672](https://github.com/ekasetiawans/flutter_background_service/commit/88917672c617b47691f71f964ee7ff8bd9f1d6f3)) + - **DOCS**: change method name. ([9f05e7f6](https://github.com/ekasetiawans/flutter_background_service/commit/9f05e7f6a260d8f63788cb21e8e7c2cdc91769eb)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +#### `flutter_background_service_android` - `v6.0.0` + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve entrypoint with args. ([5abacbe5](https://github.com/ekasetiawans/flutter_background_service/commit/5abacbe57f239d9ce1667e643d81d6b17f873f5c)) + - **PERF**: using exact alarm for watchdog receiver. ([6dba6670](https://github.com/ekasetiawans/flutter_background_service/commit/6dba6670965a24b9b0657ad0abc793db850a982b)) + - **PERF**: improve android background service. ([e01a3fa2](https://github.com/ekasetiawans/flutter_background_service/commit/e01a3fa2938479f31a525c23ff888c03b496fa70)) + - **FIX**: We still need to check service is running or not. ([280a603e](https://github.com/ekasetiawans/flutter_background_service/commit/280a603ee4fff39e2d0d0cd043dd6ba6f0941ee1)) + - **FIX**: Issue created by [#336](https://github.com/ekasetiawans/flutter_background_service/issues/336). ([6fedeed2](https://github.com/ekasetiawans/flutter_background_service/commit/6fedeed253d2648d876b9a2e3e5a30967934a81a)) + - **FIX**: added proguard for android plugin. ([0d7ac8a6](https://github.com/ekasetiawans/flutter_background_service/commit/0d7ac8a698b339af5931cb3b3e18c4b7f2e2670f)) + - **FIX**: make final variable for backward compatibility of gradle. ([d7087ba0](https://github.com/ekasetiawans/flutter_background_service/commit/d7087ba07a580e7d16d4e416cde43ddfb531e664)) + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + - **FIX**: wakelock not released. ([e427f3b7](https://github.com/ekasetiawans/flutter_background_service/commit/e427f3b70138ec26f9671c2617f9061f25eade6f)) + - **FIX**: autoStartOnBootMode [#160](https://github.com/ekasetiawans/flutter_background_service/issues/160). ([16a785a3](https://github.com/ekasetiawans/flutter_background_service/commit/16a785a3cbcb4226321ddddf681b6554196fa4db)) + - **FIX**: release wakelock. ([c0830250](https://github.com/ekasetiawans/flutter_background_service/commit/c0830250b90a1ba6e2543a1bb25a13fba59a56b7)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FEAT**: added QUICKBOOT_POWERON action to intent-filter. ([46f08173](https://github.com/ekasetiawans/flutter_background_service/commit/46f08173cfb54795fb707bd521d8ed94db75cad5)) + - **FEAT**: revert to single process. ([515dde6a](https://github.com/ekasetiawans/flutter_background_service/commit/515dde6a49e50087c6f613ff0de8e1bd111a315b)) + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + - **FEAT**(android): expose notification id for foreground service. ([47b7089c](https://github.com/ekasetiawans/flutter_background_service/commit/47b7089c5e4ab18f3a35558d6c7ec2d50fc8d3f1)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: autoStartOnBoot now using it's own argument. ([036669dc](https://github.com/ekasetiawans/flutter_background_service/commit/036669dc4383e938f09f88d9d8a248afbf918cf8)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +#### `flutter_background_service_ios` - `v5.0.0` + + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **REFACTOR**: update BGTaskScheduler flow. ([414bb21b](https://github.com/ekasetiawans/flutter_background_service/commit/414bb21b4d0af6112491fb81ee3246b7ef8a5c5b)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + - **PERF**: cancel old schedule. ([bfca5773](https://github.com/ekasetiawans/flutter_background_service/commit/bfca577324345f64faca562e32bad42ed16e92b4)) + - **FIX**: ios onBackground. ([0b1101be](https://github.com/ekasetiawans/flutter_background_service/commit/0b1101befa66f5d1f200c6a999f7e55c876f2a10)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FIX**: handle null safety. ([77513387](https://github.com/ekasetiawans/flutter_background_service/commit/775133879a1693154cf14181c3ac780aa7001710)) + - **FIX**: added pragma vm:entry-point to ios. ([7b44a2a4](https://github.com/ekasetiawans/flutter_background_service/commit/7b44a2a4ae977bd723874900eca689435989cfcd)) + - **FIX**: swift compile error. ([b75128ad](https://github.com/ekasetiawans/flutter_background_service/commit/b75128ad3100b4e505e4a3f8a037b07b9be547ad)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + - **FEAT**: onForeground and onBackground now optional. ([9dfcc4d4](https://github.com/ekasetiawans/flutter_background_service/commit/9dfcc4d4f4fea0f3b8ca0fbb47e3d127af3bc68d)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +#### `flutter_background_service_platform_interface` - `v5.0.0` + + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **FIX**: remove duplicated properties. ([891c2029](https://github.com/ekasetiawans/flutter_background_service/commit/891c20291df9612810035219af98d732d99d200c)) + - **FIX**: missing foregroundServiceNotificationId. ([e49f6137](https://github.com/ekasetiawans/flutter_background_service/commit/e49f613726120f144b04e2246c43360756d57e5b)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: method channel. ([1a1e3527](https://github.com/ekasetiawans/flutter_background_service/commit/1a1e3527465a4ede4c188b4e1aa51ce552e697c1)) + - **FEAT**: Updated configs. ([7af1961d](https://github.com/ekasetiawans/flutter_background_service/commit/7af1961def1625d7a5314812c1f794e327f53ce7)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: introduce ServiceInstance. ([425279b0](https://github.com/ekasetiawans/flutter_background_service/commit/425279b09378fbcd8e66295ce526f2c4f15d741c)) + - **BREAKING** **CHANGE**: supported only flutter 2.0.0 and newer. ([be0c32f8](https://github.com/ekasetiawans/flutter_background_service/commit/be0c32f8200dcce44ddce67461c333d6d0ef287c)) + + +## 2023-08-07 + +### Changes + +--- + +Packages with breaking changes: + + - [`flutter_background_service` - `v4.0.0`](#flutter_background_service---v400) + - [`flutter_background_service_android` - `v5.0.0`](#flutter_background_service_android---v500) + - [`flutter_background_service_ios` - `v4.0.0`](#flutter_background_service_ios---v400) + - [`flutter_background_service_platform_interface` - `v4.0.0`](#flutter_background_service_platform_interface---v400) + +Packages with other changes: + + - There are no other changes in this release. + +--- + +#### `flutter_background_service` - `v4.0.0` + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **REFACTOR**: fix sampe project dependency version. ([a83b9f62](https://github.com/ekasetiawans/flutter_background_service/commit/a83b9f62dd0d16f8bd23657ef1f36cb7d51fb0fa)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FIX**: added @pragma. ([0f90cc7d](https://github.com/ekasetiawans/flutter_background_service/commit/0f90cc7d6f1ae9b0e2ab6132151e27b88814afe1)) + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + - **FIX**: wrong dependency version. ([34e66e13](https://github.com/ekasetiawans/flutter_background_service/commit/34e66e13f04afe760d7b4087cc7052756dcb2a9c)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + - **FIX**: dependencies version. ([4e89b5e9](https://github.com/ekasetiawans/flutter_background_service/commit/4e89b5e9e5aa55074e1b10b41ea057c4b1b0bfcb)) + - **FEAT**: enhance notification icon readme. ([52e7e6ea](https://github.com/ekasetiawans/flutter_background_service/commit/52e7e6ea8bdff67924d93ce716b395bdbba2a48b)) + - **FEAT**: enhance notification icon readme. ([4d699fb0](https://github.com/ekasetiawans/flutter_background_service/commit/4d699fb03b83eae09bc3696f443a8e36092c8789)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + - **FEAT**: update dependencies. ([afc90fcc](https://github.com/ekasetiawans/flutter_background_service/commit/afc90fcc07b39954147dd24915258c96863e573e)) + - **FEAT**: managed with melos. ([2313273a](https://github.com/ekasetiawans/flutter_background_service/commit/2313273a3e728e37e2fb973ccc146841c8af48da)) + - **DOCS**: updated README.md. ([9345b16f](https://github.com/ekasetiawans/flutter_background_service/commit/9345b16f7c69e7acac1ea5d8a5985b97092a1220)) + - **DOCS**: updated README. ([f9e96ab4](https://github.com/ekasetiawans/flutter_background_service/commit/f9e96ab4978f348342703cf1de011bc59f6b9e4c)) + - **DOCS**: update README. ([5fc18ced](https://github.com/ekasetiawans/flutter_background_service/commit/5fc18ced43cc7fc1df3209eaa21ef9d424d41779)) + - **DOCS**: add documentation on configure method. ([b9612afe](https://github.com/ekasetiawans/flutter_background_service/commit/b9612afe593e766e740c69ee01a04b4f9d2ec83a)) + - **DOCS**: update FAQ. ([53215976](https://github.com/ekasetiawans/flutter_background_service/commit/532159768bc4a14701940c8166440bb1940aa1b5)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: updated README. ([2fc9ae66](https://github.com/ekasetiawans/flutter_background_service/commit/2fc9ae66f5538ab45f3690cdaee94f89b31f16e2)) + - **DOCS**: update example project for custom notification. ([d1e90d86](https://github.com/ekasetiawans/flutter_background_service/commit/d1e90d864d281747ab40170e22d91601b29927a6)) + - **DOCS**: update README. ([caf8125c](https://github.com/ekasetiawans/flutter_background_service/commit/caf8125cf557b009e06995fcc7ea8a006eba3dae)) + - **DOCS**: update README. ([88917672](https://github.com/ekasetiawans/flutter_background_service/commit/88917672c617b47691f71f964ee7ff8bd9f1d6f3)) + - **DOCS**: change method name. ([9f05e7f6](https://github.com/ekasetiawans/flutter_background_service/commit/9f05e7f6a260d8f63788cb21e8e7c2cdc91769eb)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +#### `flutter_background_service_android` - `v5.0.0` + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve entrypoint with args. ([5abacbe5](https://github.com/ekasetiawans/flutter_background_service/commit/5abacbe57f239d9ce1667e643d81d6b17f873f5c)) + - **PERF**: using exact alarm for watchdog receiver. ([6dba6670](https://github.com/ekasetiawans/flutter_background_service/commit/6dba6670965a24b9b0657ad0abc793db850a982b)) + - **PERF**: improve android background service. ([e01a3fa2](https://github.com/ekasetiawans/flutter_background_service/commit/e01a3fa2938479f31a525c23ff888c03b496fa70)) + - **FIX**: We still need to check service is running or not. ([280a603e](https://github.com/ekasetiawans/flutter_background_service/commit/280a603ee4fff39e2d0d0cd043dd6ba6f0941ee1)) + - **FIX**: Issue created by [#336](https://github.com/ekasetiawans/flutter_background_service/issues/336). ([6fedeed2](https://github.com/ekasetiawans/flutter_background_service/commit/6fedeed253d2648d876b9a2e3e5a30967934a81a)) + - **FIX**: added proguard for android plugin. ([0d7ac8a6](https://github.com/ekasetiawans/flutter_background_service/commit/0d7ac8a698b339af5931cb3b3e18c4b7f2e2670f)) + - **FIX**: make final variable for backward compatibility of gradle. ([d7087ba0](https://github.com/ekasetiawans/flutter_background_service/commit/d7087ba07a580e7d16d4e416cde43ddfb531e664)) + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + - **FIX**: wakelock not released. ([e427f3b7](https://github.com/ekasetiawans/flutter_background_service/commit/e427f3b70138ec26f9671c2617f9061f25eade6f)) + - **FIX**: autoStartOnBootMode [#160](https://github.com/ekasetiawans/flutter_background_service/issues/160). ([16a785a3](https://github.com/ekasetiawans/flutter_background_service/commit/16a785a3cbcb4226321ddddf681b6554196fa4db)) + - **FIX**: release wakelock. ([c0830250](https://github.com/ekasetiawans/flutter_background_service/commit/c0830250b90a1ba6e2543a1bb25a13fba59a56b7)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FEAT**: added QUICKBOOT_POWERON action to intent-filter. ([46f08173](https://github.com/ekasetiawans/flutter_background_service/commit/46f08173cfb54795fb707bd521d8ed94db75cad5)) + - **FEAT**: revert to single process. ([515dde6a](https://github.com/ekasetiawans/flutter_background_service/commit/515dde6a49e50087c6f613ff0de8e1bd111a315b)) + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + - **FEAT**(android): expose notification id for foreground service. ([47b7089c](https://github.com/ekasetiawans/flutter_background_service/commit/47b7089c5e4ab18f3a35558d6c7ec2d50fc8d3f1)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: autoStartOnBoot now using it's own argument. ([036669dc](https://github.com/ekasetiawans/flutter_background_service/commit/036669dc4383e938f09f88d9d8a248afbf918cf8)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +#### `flutter_background_service_ios` - `v4.0.0` + + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **REFACTOR**: update BGTaskScheduler flow. ([414bb21b](https://github.com/ekasetiawans/flutter_background_service/commit/414bb21b4d0af6112491fb81ee3246b7ef8a5c5b)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + - **PERF**: cancel old schedule. ([bfca5773](https://github.com/ekasetiawans/flutter_background_service/commit/bfca577324345f64faca562e32bad42ed16e92b4)) + - **FIX**: ios onBackground. ([0b1101be](https://github.com/ekasetiawans/flutter_background_service/commit/0b1101befa66f5d1f200c6a999f7e55c876f2a10)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FIX**: handle null safety. ([77513387](https://github.com/ekasetiawans/flutter_background_service/commit/775133879a1693154cf14181c3ac780aa7001710)) + - **FIX**: added pragma vm:entry-point to ios. ([7b44a2a4](https://github.com/ekasetiawans/flutter_background_service/commit/7b44a2a4ae977bd723874900eca689435989cfcd)) + - **FIX**: swift compile error. ([b75128ad](https://github.com/ekasetiawans/flutter_background_service/commit/b75128ad3100b4e505e4a3f8a037b07b9be547ad)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + - **FEAT**: onForeground and onBackground now optional. ([9dfcc4d4](https://github.com/ekasetiawans/flutter_background_service/commit/9dfcc4d4f4fea0f3b8ca0fbb47e3d127af3bc68d)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +#### `flutter_background_service_platform_interface` - `v4.0.0` + + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **FIX**: remove duplicated properties. ([891c2029](https://github.com/ekasetiawans/flutter_background_service/commit/891c20291df9612810035219af98d732d99d200c)) + - **FIX**: missing foregroundServiceNotificationId. ([e49f6137](https://github.com/ekasetiawans/flutter_background_service/commit/e49f613726120f144b04e2246c43360756d57e5b)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: method channel. ([1a1e3527](https://github.com/ekasetiawans/flutter_background_service/commit/1a1e3527465a4ede4c188b4e1aa51ce552e697c1)) + - **FEAT**: Updated configs. ([7af1961d](https://github.com/ekasetiawans/flutter_background_service/commit/7af1961def1625d7a5314812c1f794e327f53ce7)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: introduce ServiceInstance. ([425279b0](https://github.com/ekasetiawans/flutter_background_service/commit/425279b09378fbcd8e66295ce526f2c4f15d741c)) + - **BREAKING** **CHANGE**: supported only flutter 2.0.0 and newer. ([be0c32f8](https://github.com/ekasetiawans/flutter_background_service/commit/be0c32f8200dcce44ddce67461c333d6d0ef287c)) + + +## 2023-08-07 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v4.0.2`](#flutter_background_service_android---v402) + - [`flutter_background_service` - `v3.0.2`](#flutter_background_service---v302) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v3.0.2` + +--- + +#### `flutter_background_service_android` - `v4.0.2` + + - **FIX**: We still need to check service is running or not. ([280a603e](https://github.com/ekasetiawans/flutter_background_service/commit/280a603ee4fff39e2d0d0cd043dd6ba6f0941ee1)) + - **FIX**: Issue created by [#336](https://github.com/ekasetiawans/flutter_background_service/issues/336). ([6fedeed2](https://github.com/ekasetiawans/flutter_background_service/commit/6fedeed253d2648d876b9a2e3e5a30967934a81a)) + + +## 2023-06-14 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v3.0.1`](#flutter_background_service---v301) + - [`flutter_background_service_android` - `v4.0.1`](#flutter_background_service_android---v401) + +--- + +#### `flutter_background_service` - `v3.0.1` + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + +#### `flutter_background_service_android` - `v4.0.1` + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + + +## 2023-06-14 + +### Changes + +--- + +Packages with breaking changes: + + - [`flutter_background_service` - `v3.0.0`](#flutter_background_service---v300) + - [`flutter_background_service_android` - `v4.0.0`](#flutter_background_service_android---v400) + - [`flutter_background_service_ios` - `v3.0.0`](#flutter_background_service_ios---v300) + - [`flutter_background_service_platform_interface` - `v3.0.0`](#flutter_background_service_platform_interface---v300) + +Packages with other changes: + + - There are no other changes in this release. + +--- + +#### `flutter_background_service` - `v3.0.0` + + - **FEAT**: enhance notification icon readme. ([52e7e6ea](https://github.com/ekasetiawans/flutter_background_service/commit/52e7e6ea8bdff67924d93ce716b395bdbba2a48b)) + - **FEAT**: enhance notification icon readme. ([4d699fb0](https://github.com/ekasetiawans/flutter_background_service/commit/4d699fb03b83eae09bc3696f443a8e36092c8789)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + +#### `flutter_background_service_android` - `v4.0.0` + + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + +#### `flutter_background_service_ios` - `v3.0.0` + + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + +#### `flutter_background_service_platform_interface` - `v3.0.0` + + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + + +## 2022-12-14 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.4.6`](#flutter_background_service---v246) + +--- + +#### `flutter_background_service` - `v2.4.6` + + - **DOCS**: updated README.md. ([9345b16f](https://github.com/ekasetiawans/flutter_background_service/commit/9345b16f7c69e7acac1ea5d8a5985b97092a1220)) + + +## 2022-10-12 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.4.5`](#flutter_background_service---v245) + +--- + +#### `flutter_background_service` - `v2.4.5` + + - **DOCS**: updated README. ([f9e96ab4](https://github.com/ekasetiawans/flutter_background_service/commit/f9e96ab4978f348342703cf1de011bc59f6b9e4c)) + + +## 2022-10-12 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v3.0.2`](#flutter_background_service_android---v302) + - [`flutter_background_service` - `v2.4.4`](#flutter_background_service---v244) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.4.4` + +--- + +#### `flutter_background_service_android` - `v3.0.2` + + - **FIX**: added proguard for android plugin. ([0d7ac8a6](https://github.com/ekasetiawans/flutter_background_service/commit/0d7ac8a698b339af5931cb3b3e18c4b7f2e2670f)) + + +## 2022-09-29 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.4.3`](#flutter_background_service---v243) + +--- + +#### `flutter_background_service` - `v2.4.3` + + - **DOCS**: update README. ([5fc18ced](https://github.com/ekasetiawans/flutter_background_service/commit/5fc18ced43cc7fc1df3209eaa21ef9d424d41779)) + + +## 2022-09-29 + +### Changes + +--- + +Packages with breaking changes: + + - [`flutter_background_service_android` - `v3.0.0`](#flutter_background_service_android---v300) + +Packages with other changes: + + - [`flutter_background_service` - `v2.4.2`](#flutter_background_service---v242) + - [`flutter_background_service_ios` - `v2.4.0`](#flutter_background_service_ios---v240) + - [`flutter_background_service_platform_interface` - `v2.2.0`](#flutter_background_service_platform_interface---v220) + +--- + +#### `flutter_background_service_android` - `v3.0.0` + + - **BREAKING** **FEAT**: autoStartOnBoot now using it's own argument. ([036669dc](https://github.com/ekasetiawans/flutter_background_service/commit/036669dc4383e938f09f88d9d8a248afbf918cf8)) + +#### `flutter_background_service` - `v2.4.2` + + - **DOCS**: add documentation on configure method. ([b9612afe](https://github.com/ekasetiawans/flutter_background_service/commit/b9612afe593e766e740c69ee01a04b4f9d2ec83a)) + +#### `flutter_background_service_ios` - `v2.4.0` + + - **FEAT**: onForeground and onBackground now optional. ([9dfcc4d4](https://github.com/ekasetiawans/flutter_background_service/commit/9dfcc4d4f4fea0f3b8ca0fbb47e3d127af3bc68d)) + +#### `flutter_background_service_platform_interface` - `v2.2.0` + + - **FEAT**: Updated configs. ([7af1961d](https://github.com/ekasetiawans/flutter_background_service/commit/7af1961def1625d7a5314812c1f794e327f53ce7)) + + +## 2022-09-28 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.4.1`](#flutter_background_service---v241) + - [`flutter_background_service_android` - `v2.5.4`](#flutter_background_service_android---v254) + - [`flutter_background_service_ios` - `v2.3.1`](#flutter_background_service_ios---v231) + +--- + +#### `flutter_background_service` - `v2.4.1` + + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + +#### `flutter_background_service_android` - `v2.5.4` + + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + +#### `flutter_background_service_ios` - `v2.3.1` + + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + + +## 2022-09-28 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.4.0`](#flutter_background_service---v240) + - [`flutter_background_service_android` - `v2.5.3`](#flutter_background_service_android---v253) + - [`flutter_background_service_ios` - `v2.3.0`](#flutter_background_service_ios---v230) + +--- + +#### `flutter_background_service` - `v2.4.0` + + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + +#### `flutter_background_service_android` - `v2.5.3` + + - **PERF**: improve entrypoint with args. ([5abacbe5](https://github.com/ekasetiawans/flutter_background_service/commit/5abacbe57f239d9ce1667e643d81d6b17f873f5c)) + +#### `flutter_background_service_ios` - `v2.3.0` + + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **PERF**: cancel old schedule. ([bfca5773](https://github.com/ekasetiawans/flutter_background_service/commit/bfca577324345f64faca562e32bad42ed16e92b4)) + - **FIX**: ios onBackground. ([0b1101be](https://github.com/ekasetiawans/flutter_background_service/commit/0b1101befa66f5d1f200c6a999f7e55c876f2a10)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + + +## 2022-09-27 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v2.5.2`](#flutter_background_service_android---v252) + - [`flutter_background_service` - `v2.3.10`](#flutter_background_service---v2310) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.3.10` + +--- + +#### `flutter_background_service_android` - `v2.5.2` + + - **PERF**: using exact alarm for watchdog receiver. ([6dba6670](https://github.com/ekasetiawans/flutter_background_service/commit/6dba6670965a24b9b0657ad0abc793db850a982b)) + + +## 2022-09-21 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.3.9`](#flutter_background_service---v239) + - [`flutter_background_service_android` - `v2.5.0`](#flutter_background_service_android---v250) + - [`flutter_background_service_ios` - `v2.2.5`](#flutter_background_service_ios---v225) + +--- + +#### `flutter_background_service` - `v2.3.9` + + - **FIX**: added @pragma. ([0f90cc7d](https://github.com/ekasetiawans/flutter_background_service/commit/0f90cc7d6f1ae9b0e2ab6132151e27b88814afe1)) + - **DOCS**: update FAQ. ([53215976](https://github.com/ekasetiawans/flutter_background_service/commit/532159768bc4a14701940c8166440bb1940aa1b5)) + +#### `flutter_background_service_android` - `v2.5.0` + + - **FEAT**: added QUICKBOOT_POWERON action to intent-filter. ([46f08173](https://github.com/ekasetiawans/flutter_background_service/commit/46f08173cfb54795fb707bd521d8ed94db75cad5)) + +#### `flutter_background_service_ios` - `v2.2.5` + + - **FIX**: handle null safety. ([77513387](https://github.com/ekasetiawans/flutter_background_service/commit/775133879a1693154cf14181c3ac780aa7001710)) + + +## 2022-09-20 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v2.4.0`](#flutter_background_service_android---v240) + - [`flutter_background_service` - `v2.3.8`](#flutter_background_service---v238) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.3.8` + +--- + +#### `flutter_background_service_android` - `v2.4.0` + + - **FEAT**: revert to single process. ([515dde6a](https://github.com/ekasetiawans/flutter_background_service/commit/515dde6a49e50087c6f613ff0de8e1bd111a315b)) + + +## 2022-09-19 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v2.3.4`](#flutter_background_service_android---v234) + - [`flutter_background_service_platform_interface` - `v2.1.4`](#flutter_background_service_platform_interface---v214) + - [`flutter_background_service` - `v2.3.7`](#flutter_background_service---v237) + - [`flutter_background_service_ios` - `v2.2.4`](#flutter_background_service_ios---v224) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.3.7` + - `flutter_background_service_ios` - `v2.2.4` + +--- + +#### `flutter_background_service_android` - `v2.3.4` + + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + +#### `flutter_background_service_platform_interface` - `v2.1.4` + + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + + +## 2022-09-19 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v2.3.3`](#flutter_background_service_android---v233) + - [`flutter_background_service` - `v2.3.6`](#flutter_background_service---v236) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.3.6` + +--- + +#### `flutter_background_service_android` - `v2.3.3` + + - **FIX**: make final variable for backward compatibility of gradle. ([d7087ba0](https://github.com/ekasetiawans/flutter_background_service/commit/d7087ba07a580e7d16d4e416cde43ddfb531e664)) + + +## 2022-09-15 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.3.5`](#flutter_background_service---v235) + - [`flutter_background_service_android` - `v2.3.2`](#flutter_background_service_android---v232) + +--- + +#### `flutter_background_service` - `v2.3.5` + + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + +#### `flutter_background_service_android` - `v2.3.2` + + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: updated README. ([3885e301](https://github.com/ekasetiawans/flutter_background_service/commit/3885e3017729a557b0b0b7ccdb968692ba7c8a52)) + + +## 2022-09-15 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.3.4`](#flutter_background_service---v234) + - [`flutter_background_service_android` - `v2.3.1`](#flutter_background_service_android---v231) + - [`flutter_background_service_ios` - `v2.2.3`](#flutter_background_service_ios---v223) + - [`flutter_background_service_platform_interface` - `v2.1.3`](#flutter_background_service_platform_interface---v213) + +--- + +#### `flutter_background_service` - `v2.3.4` + + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + +#### `flutter_background_service_android` - `v2.3.1` + + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + +#### `flutter_background_service_ios` - `v2.2.3` + + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + +#### `flutter_background_service_platform_interface` - `v2.1.3` + + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + + +## 2022-09-15 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.3.3`](#flutter_background_service---v233) + +--- + +#### `flutter_background_service` - `v2.3.3` + + - **FIX**: wrong dependency version. ([34e66e13](https://github.com/ekasetiawans/flutter_background_service/commit/34e66e13f04afe760d7b4087cc7052756dcb2a9c)) + + +## 2022-09-15 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.3.2`](#flutter_background_service---v232) + +--- + +#### `flutter_background_service` - `v2.3.2` + + - **DOCS**: updated README. ([2fc9ae66](https://github.com/ekasetiawans/flutter_background_service/commit/2fc9ae66f5538ab45f3690cdaee94f89b31f16e2)) + - **DOCS**: updated README. ([3885e301](https://github.com/ekasetiawans/flutter_background_service/commit/3885e3017729a557b0b0b7ccdb968692ba7c8a52)) + + +## 2022-09-15 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.3.0`](#flutter_background_service---v230) + - [`flutter_background_service_android` - `v2.3.0`](#flutter_background_service_android---v230) + +--- + +#### `flutter_background_service` - `v2.3.0` + + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + +#### `flutter_background_service_android` - `v2.3.0` + + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + + +## 2022-09-14 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.2.4`](#flutter_background_service---v224) + - [`flutter_background_service_platform_interface` - `v2.1.2`](#flutter_background_service_platform_interface---v212) + - [`flutter_background_service_ios` - `v2.2.2`](#flutter_background_service_ios---v222) + - [`flutter_background_service_android` - `v2.2.2`](#flutter_background_service_android---v222) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service_ios` - `v2.2.2` + - `flutter_background_service_android` - `v2.2.2` + +--- + +#### `flutter_background_service` - `v2.2.4` + + - **DOCS**: update example project for custom notification. ([d1e90d86](https://github.com/ekasetiawans/flutter_background_service/commit/d1e90d864d281747ab40170e22d91601b29927a6)) + +#### `flutter_background_service_platform_interface` - `v2.1.2` + + - **FIX**: remove duplicated properties. ([891c2029](https://github.com/ekasetiawans/flutter_background_service/commit/891c20291df9612810035219af98d732d99d200c)) + + +## 2022-09-14 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_platform_interface` - `v2.1.1`](#flutter_background_service_platform_interface---v211) + - [`flutter_background_service_android` - `v2.2.1`](#flutter_background_service_android---v221) + - [`flutter_background_service_ios` - `v2.2.1`](#flutter_background_service_ios---v221) + - [`flutter_background_service` - `v2.2.3`](#flutter_background_service---v223) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service_android` - `v2.2.1` + - `flutter_background_service_ios` - `v2.2.1` + - `flutter_background_service` - `v2.2.3` + +--- + +#### `flutter_background_service_platform_interface` - `v2.1.1` + + - **FIX**: missing foregroundServiceNotificationId. ([e49f6137](https://github.com/ekasetiawans/flutter_background_service/commit/e49f613726120f144b04e2246c43360756d57e5b)) + + +## 2022-09-14 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v2.2.0`](#flutter_background_service_android---v220) + - [`flutter_background_service` - `v2.2.2`](#flutter_background_service---v222) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.2.2` + +--- + +#### `flutter_background_service_android` - `v2.2.0` + + - **FEAT**: expose notification id for foreground service. ([47b7089c](https://github.com/ekasetiawans/flutter_background_service/commit/47b7089c5e4ab18f3a35558d6c7ec2d50fc8d3f1)) + + +## 2022-09-14 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v2.1.1`](#flutter_background_service_android---v211) + - [`flutter_background_service` - `v2.2.1`](#flutter_background_service---v221) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.2.1` + +--- + +#### `flutter_background_service_android` - `v2.1.1` + + - **PERF**: improve android background service. ([e01a3fa2](https://github.com/ekasetiawans/flutter_background_service/commit/e01a3fa2938479f31a525c23ff888c03b496fa70)) + + +## 2022-09-14 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.2.0`](#flutter_background_service---v220) + - [`flutter_background_service_android` - `v2.1.0`](#flutter_background_service_android---v210) + - [`flutter_background_service_ios` - `v2.2.0`](#flutter_background_service_ios---v220) + - [`flutter_background_service_platform_interface` - `v2.1.0`](#flutter_background_service_platform_interface---v210) + +--- + +#### `flutter_background_service` - `v2.2.0` + + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + +#### `flutter_background_service_android` - `v2.1.0` + + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + +#### `flutter_background_service_ios` - `v2.2.0` + + - **FIX**: added pragma vm:entry-point to ios. ([7b44a2a4](https://github.com/ekasetiawans/flutter_background_service/commit/7b44a2a4ae977bd723874900eca689435989cfcd)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + +#### `flutter_background_service_platform_interface` - `v2.1.0` + + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + + +## 2022-06-14 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v2.0.3`](#flutter_background_service_android---v203) + - [`flutter_background_service` - `v2.1.3`](#flutter_background_service---v213) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.1.3` + +--- + +#### `flutter_background_service_android` - `v2.0.3` + + - **FIX**: wakelock not released. ([e427f3b7](https://github.com/ekasetiawans/flutter_background_service/commit/e427f3b70138ec26f9671c2617f9061f25eade6f)) + + +## 2022-05-30 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v2.0.2`](#flutter_background_service_android---v202) + - [`flutter_background_service` - `v2.1.2`](#flutter_background_service---v212) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.1.2` + +--- + +#### `flutter_background_service_android` - `v2.0.2` + + - **FIX**: autoStartOnBootMode #160. ([16a785a3](https://github.com/ekasetiawans/flutter_background_service/commit/16a785a3cbcb4226321ddddf681b6554196fa4db)) + + +## 2022-05-27 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v2.0.1`](#flutter_background_service_android---v201) + - [`flutter_background_service` - `v2.1.1`](#flutter_background_service---v211) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.1.1` + +--- + +#### `flutter_background_service_android` - `v2.0.1` + + - **FIX**: release wakelock. ([c0830250](https://github.com/ekasetiawans/flutter_background_service/commit/c0830250b90a1ba6e2543a1bb25a13fba59a56b7)) + + +## 2022-05-19 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.1.0`](#flutter_background_service---v210) + - [`flutter_background_service_ios` - `v2.1.0`](#flutter_background_service_ios---v210) + +--- + +#### `flutter_background_service` - `v2.1.0` + + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + +#### `flutter_background_service_ios` - `v2.1.0` + + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + + +## 2022-04-10 + +### Changes + +--- + +Packages with breaking changes: + + - [`flutter_background_service` - `v2.0.0`](#flutter_background_service---v200) + - [`flutter_background_service_android` - `v2.0.0`](#flutter_background_service_android---v200) + - [`flutter_background_service_ios` - `v2.0.0`](#flutter_background_service_ios---v200) + - [`flutter_background_service_platform_interface` - `v2.0.0`](#flutter_background_service_platform_interface---v200) + +Packages with other changes: + + - There are no other changes in this release. + +Packages graduated to a stable release (see pre-releases prior to the stable version for changelog entries): + + - `flutter_background_service` - `v2.0.0` + - `flutter_background_service_android` - `v2.0.0` + - `flutter_background_service_ios` - `v2.0.0` + - `flutter_background_service_platform_interface` - `v2.0.0` + +--- + +#### `flutter_background_service` - `v2.0.0` + +#### `flutter_background_service_android` - `v2.0.0` + +#### `flutter_background_service_ios` - `v2.0.0` + +#### `flutter_background_service_platform_interface` - `v2.0.0` + + +## 2022-04-08 + +### Changes + +--- + +Packages with breaking changes: + + - [`example` - `v2.0.0`](#example---v200) + +Packages with other changes: + + - There are no other changes in this release. + +--- + +#### `example` - `v2.0.0` + + - **REFACTOR**: fix sampe project dependency version. ([a83b9f62](https://github.com/ekasetiawans/flutter_background_service/commit/a83b9f62dd0d16f8bd23657ef1f36cb7d51fb0fa)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + - **FEAT**: managed with melos. ([2313273a](https://github.com/ekasetiawans/flutter_background_service/commit/2313273a3e728e37e2fb973ccc146841c8af48da)) + - **DOCS**: change method name. ([9f05e7f6](https://github.com/ekasetiawans/flutter_background_service/commit/9f05e7f6a260d8f63788cb21e8e7c2cdc91769eb)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + + +## 2022-04-08 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.0.0-dev.3`](#flutter_background_service---v200-dev3) + - [`flutter_background_service_ios` - `v2.0.0-dev.2`](#flutter_background_service_ios---v200-dev2) + +--- + +#### `flutter_background_service` - `v2.0.0-dev.3` + + - **REFACTOR**: fix sampe project dependency version. ([a83b9f62](https://github.com/ekasetiawans/flutter_background_service/commit/a83b9f62dd0d16f8bd23657ef1f36cb7d51fb0fa)) + +#### `flutter_background_service_ios` - `v2.0.0-dev.2` + + - **FIX**: swift compile error. ([b75128ad](https://github.com/ekasetiawans/flutter_background_service/commit/b75128ad3100b4e505e4a3f8a037b07b9be547ad)) + + +## 2022-04-08 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_ios` - `v2.0.0-dev.1`](#flutter_background_service_ios---v200-dev1) + - [`flutter_background_service` - `v2.0.0-dev.2`](#flutter_background_service---v200-dev2) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v2.0.0-dev.2` + +--- + +#### `flutter_background_service_ios` - `v2.0.0-dev.1` + + - **REFACTOR**: update BGTaskScheduler flow. ([414bb21b](https://github.com/ekasetiawans/flutter_background_service/commit/414bb21b4d0af6112491fb81ee3246b7ef8a5c5b)) + + +## 2022-04-05 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v2.0.0-dev.1`](#flutter_background_service---v200-dev1) + +--- + +#### `flutter_background_service` - `v2.0.0-dev.1` + + - **DOCS**: update README. ([caf8125c](https://github.com/ekasetiawans/flutter_background_service/commit/caf8125cf557b009e06995fcc7ea8a006eba3dae)) + + +## 2022-04-05 + +### Changes + +--- + +Packages with breaking changes: + + - [`flutter_background_service` - `v2.0.0-dev.0`](#flutter_background_service---v200-dev0) + - [`flutter_background_service_android` - `v2.0.0-dev.0`](#flutter_background_service_android---v200-dev0) + - [`flutter_background_service_ios` - `v2.0.0-dev.0`](#flutter_background_service_ios---v200-dev0) + - [`flutter_background_service_platform_interface` - `v2.0.0-dev.0`](#flutter_background_service_platform_interface---v200-dev0) + +Packages with other changes: + + - There are no other changes in this release. + +--- + +#### `flutter_background_service` - `v2.0.0-dev.0` + + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +#### `flutter_background_service_android` - `v2.0.0-dev.0` + + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +#### `flutter_background_service_ios` - `v2.0.0-dev.0` + + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +#### `flutter_background_service_platform_interface` - `v2.0.0-dev.0` + + - **BREAKING** **FEAT**: introduce ServiceInstance. ([425279b0](https://github.com/ekasetiawans/flutter_background_service/commit/425279b09378fbcd8e66295ce526f2c4f15d741c)) + + +## 2022-03-18 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v1.0.4`](#flutter_background_service---v104) + +--- + +#### `flutter_background_service` - `v1.0.4` + + - **DOCS**: update README. ([88917672](https://github.com/ekasetiawans/flutter_background_service/commit/88917672c617b47691f71f964ee7ff8bd9f1d6f3)) + + +## 2022-03-18 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v1.0.2`](#flutter_background_service_android---v102) + - [`flutter_background_service_ios` - `v1.0.2`](#flutter_background_service_ios---v102) + - [`flutter_background_service_platform_interface` - `v1.0.2`](#flutter_background_service_platform_interface---v102) + - [`flutter_background_service` - `v1.0.3`](#flutter_background_service---v103) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v1.0.3` + +--- + +#### `flutter_background_service_android` - `v1.0.2` + + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + +#### `flutter_background_service_ios` - `v1.0.2` + + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + +#### `flutter_background_service_platform_interface` - `v1.0.2` + + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + + +## 2022-03-18 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v1.0.1`](#flutter_background_service_android---v101) + - [`flutter_background_service_ios` - `v1.0.1`](#flutter_background_service_ios---v101) + - [`flutter_background_service_platform_interface` - `v1.0.1`](#flutter_background_service_platform_interface---v101) + - [`flutter_background_service` - `v1.0.2`](#flutter_background_service---v102) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v1.0.2` + +--- + +#### `flutter_background_service_android` - `v1.0.1` + + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + +#### `flutter_background_service_ios` - `v1.0.1` + + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + +#### `flutter_background_service_platform_interface` - `v1.0.1` + + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + + +## 2022-03-18 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v1.0.1`](#flutter_background_service---v101) + +--- + +#### `flutter_background_service` - `v1.0.1` + + - **DOCS**: change method name. ([9f05e7f6](https://github.com/ekasetiawans/flutter_background_service/commit/9f05e7f6a260d8f63788cb21e8e7c2cdc91769eb)) + + +## 2022-03-18 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_android` - `v0.0.2`](#flutter_background_service_android---v002) + - [`flutter_background_service_ios` - `v0.0.2`](#flutter_background_service_ios---v002) + - [`flutter_background_service` - `v0.2.8+5`](#flutter_background_service---v0285) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service` - `v0.2.8+5` + +--- + +#### `flutter_background_service_android` - `v0.0.2` + + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + +#### `flutter_background_service_ios` - `v0.0.2` + + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + + +## 2022-03-17 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v0.2.8+4`](#flutter_background_service---v0284) + - [`flutter_background_service_android` - `v0.0.1+3`](#flutter_background_service_android---v0013) + - [`flutter_background_service_ios` - `v0.0.1+4`](#flutter_background_service_ios---v0014) + - [`flutter_background_service_platform_interface` - `v0.0.1+3`](#flutter_background_service_platform_interface---v0013) + +--- + +#### `flutter_background_service` - `v0.2.8+4` + + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + +#### `flutter_background_service_android` - `v0.0.1+3` + + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + +#### `flutter_background_service_ios` - `v0.0.1+4` + + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + +#### `flutter_background_service_platform_interface` - `v0.0.1+3` + + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + + +## 2022-03-17 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service` - `v0.2.8+3`](#flutter_background_service---v0283) + - [`flutter_background_service_ios` - `v0.0.1+3`](#flutter_background_service_ios---v0013) + +--- + +#### `flutter_background_service` - `v0.2.8+3` + + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + +#### `flutter_background_service_ios` - `v0.0.1+3` + + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + + +## 2022-03-17 + +### Changes + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`flutter_background_service_platform_interface` - `v0.0.1+2`](#flutter_background_service_platform_interface---v0012) + - [`flutter_background_service_ios` - `v0.0.1+2`](#flutter_background_service_ios---v0012) + - [`flutter_background_service_android` - `v0.0.1+2`](#flutter_background_service_android---v0012) + - [`flutter_background_service` - `v0.2.8+2`](#flutter_background_service---v0282) + +Packages with dependency updates only: + +> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project. + + - `flutter_background_service_ios` - `v0.0.1+2` + - `flutter_background_service_android` - `v0.0.1+2` + - `flutter_background_service` - `v0.2.8+2` + +--- + +#### `flutter_background_service_platform_interface` - `v0.0.1+2` + + - **FIX**: method channel. ([1a1e3527](https://github.com/ekasetiawans/flutter_background_service/commit/1a1e3527465a4ede4c188b4e1aa51ce552e697c1)) -* TODO: Describe initial release. \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 6f3b2ac9..00000000 --- a/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright 2017 The Chromium Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of Google Inc. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md index 449163fc..b94b0048 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,272 @@ -# flutter_background_service - A flutter plugin for execute dart code in background. +## Support me to maintain this plugin continously with a cup of coffee. + +[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/ekasetiawans) + ## Android -- No additional setting is required. - To change notification icon, just add drawable icon with name `ic_bg_service_small`. +> **WARNING**: +> +> Please make sure your project already use the version of gradle tools below: +> - in android/build.gradle ```classpath 'com.android.tools.build:gradle:7.4.2'``` +> - in android/build.gradle ```ext.kotlin_version = '1.8.10'``` +> - in android/gradle/wrapper/gradle-wrapper.properties ```distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip``` + +### Configuration required for Foreground Services on Android 14+ (SDK 34) + +Applications that target SDK 34 and use foreground services need to include some additional configuration to declare the type of foreground service they use: + +* Determine the type or types of foreground service your app requires by consulting [the documentation](https://developer.android.com/about/versions/14/changes/fgs-types-required) + +* Add the corresponding permission to your `android/app/src/main/AndroidManifest.xml` file: + +```xml + + ... + + + + + + + + + + + + + ... + ... + + +``` + +* Add the corresponding foreground service types to your AndroidConfiguration class: +```dart +await service.configure( + // IOS configuration + androidConfiguration: AndroidConfiguration( + ... + // Add this + foregroundServiceTypes: [AndroidForegroundType.WhatForegroundServiceTypeDoYouWant] + // Example: + // foregroundServiceTypes: [AndroidForegroundType.mediaPlayback] + ), + ); +``` + +> **WARNING**: +> * YOU MUST MAKE SURE ANY REQUIRED PERMISSIONS TO BE GRANTED BEFORE YOU START THE SERVICE +> * THE TYPES YOU PUT IN foregroundServiceTypes, MUST BE DECLARED IN MANIFEST + + +### Using custom notification for Foreground Service +You can make your own custom notification for foreground service. It can give you more power to make notifications more attractive to users, for example adding progressbars, buttons, actions, etc. The example below is using [flutter_local_notifications](https://pub.dev/packages/flutter_local_notifications) plugin, but you can use any other notification plugin. You can follow how to make it below: + +- Notification Channel +```dart + +Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + await initializeService(); + + runApp(MyApp()); +} + +// this will be used as notification channel id +const notificationChannelId = 'my_foreground'; + +// this will be used for notification id, So you can update your custom notification with this id. +const notificationId = 888; + +Future initializeService() async { + final service = FlutterBackgroundService(); + + const AndroidNotificationChannel channel = AndroidNotificationChannel( + notificationChannelId, // id + 'MY FOREGROUND SERVICE', // title + description: + 'This channel is used for important notifications.', // description + importance: Importance.low, // importance must be at low or higher level + ); + + final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = + FlutterLocalNotificationsPlugin(); + + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + ?.createNotificationChannel(channel); + + await service.configure( + androidConfiguration: AndroidConfiguration( + // this will be executed when app is in foreground or background in separated isolate + onStart: onStart, + + // auto start service + autoStart: true, + isForegroundMode: true, + + notificationChannelId: notificationChannelId, // this must match with notification channel you created above. + initialNotificationTitle: 'AWESOME SERVICE', + initialNotificationContent: 'Initializing', + foregroundServiceNotificationId: notificationId, + ), + ... +``` + +- Update notification info + +```dart + +Future onStart(ServiceInstance service) async { + // Only available for flutter 3.0.0 and later + DartPluginRegistrant.ensureInitialized(); + + final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = + FlutterLocalNotificationsPlugin(); + + // bring to foreground + Timer.periodic(const Duration(seconds: 1), (timer) async { + if (service is AndroidServiceInstance) { + if (await service.isForegroundService()) { + flutterLocalNotificationsPlugin.show( + notificationId, + 'COOL SERVICE', + 'Awesome ${DateTime.now()}', + const NotificationDetails( + android: AndroidNotificationDetails( + notificationChannelId, + 'MY FOREGROUND SERVICE', + icon: 'ic_bg_service_small', + ongoing: true, + ), + ), + ); + } + } + }); +} +``` + + +### Using Background Service Even when The Application Is Closed + +You can use this feature in order to execute code in background. +Very useful to fetch realtime data from a server and push notifications. + +> **Must Know**: +> * ``` isForegroundMode: false ``` : The background mode requires running in release mode and requires disabling battery optimization so that the service stays up when the user closes the application. +> * ``` isForegroundMode: true ``` : Displays a silent notification when used according to [Android's Policy](https://developer.android.com/develop/background-work/services) + + +- Simple implementation using Socket.io +```dart +import 'dart:async'; +import 'dart:ui'; +import 'package:socket_io_client/socket_io_client.dart' as io; +import 'package:flutter/material.dart'; +import 'package:flutter_background_service/flutter_background_service.dart'; + +Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + await initializeService(); + + runApp(MyApp()); +} + +void startBackgroundService() { + final service = FlutterBackgroundService(); + service.startService(); +} + +void stopBackgroundService() { + final service = FlutterBackgroundService(); + service.invoke("stop"); +} + +Future initializeService() async { + final service = FlutterBackgroundService(); + + await service.configure( + iosConfiguration: IosConfiguration( + autoStart: true, + onForeground: onStart, + onBackground: onIosBackground, + ), + androidConfiguration: AndroidConfiguration( + autoStart: true, + onStart: onStart, + isForegroundMode: false, + autoStartOnBoot: true, + ), + ); +} + +@pragma('vm:entry-point') +Future onIosBackground(ServiceInstance service) async { + WidgetsFlutterBinding.ensureInitialized(); + DartPluginRegistrant.ensureInitialized(); + + return true; +} + +@pragma('vm:entry-point') +void onStart(ServiceInstance service) async { + final socket = io.io("your-server-url", { + 'transports': ['websocket'], + 'autoConnect': true, + }); + socket.onConnect((_) { + print('Connected. Socket ID: ${socket.id}'); + // Implement your socket logic here + // For example, you can listen for events or send data + }); + + socket.onDisconnect((_) { + print('Disconnected'); + }); + socket.on("event-name", (data) { + //do something here like pushing a notification + }); + service.on("stop").listen((event) { + service.stopSelf(); + print("background process is now stopped"); + }); + + service.on("start").listen((event) {}); + + Timer.periodic(const Duration(seconds: 1), (timer) { + socket.emit("event-name", "your-message"); + print("service is successfully running ${DateTime.now().second}"); + }); +} +``` + ## iOS - Enable `background_fetch` capability in xcode (optional), if you wish ios to execute `IosConfiguration.onBackground` callback. -- For iOS 13 (using `BGTaskScheduler`), insert lines below into your ios/Runner/Info.plist +- For iOS 13 and Later (using `BGTaskScheduler`), insert lines below into your ios/Runner/Info.plist ```plist BGTaskSchedulerPermittedIdentifiers @@ -20,12 +275,45 @@ A flutter plugin for execute dart code in background. ``` +- You can also using your own custom identifier +In `ios/Runner/AppDelegate.swift` add line below + +```swift +import UIKit +import Flutter +import flutter_background_service_ios // add this + +@UIApplicationMain +@objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + /// Add this line + SwiftFlutterBackgroundServicePlugin.taskIdentifier = "your.custom.task.identifier" + + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +} +``` + ## Usage -- Call `FlutterBackgroundService.configure` to configure handler that will be executed by the Service. +- Call `FlutterBackgroundService.configure()` to configure handler that will be executed by the Service. + +> It's highly recommended to call this method in `main()` method to ensure the callback handler updated. + - Call `FlutterBackgroundService.start` to start the Service if `autoStart` is not enabled. -- Since the Service using Isolates, You won't be able to share reference between UI and Service. You can communicate between UI and Service using `sendData()` and `onDataReceived`. +- Since the Service using Isolates, You won't be able to share reference between UI and Service. You can communicate between UI and Service using `invoke()` and `on(String method)`. + +## Migration + +- `sendData()` renamed to `invoke(String method)` +- `onDataReceived()` renamed to `on(String method)` +- Now you have to use `ServiceInstance` object inside `onStart` method instead of creating a new `FlutterBackgroundService` object. See the example project. +- Only use `FlutterBackgroundService` class in UI Isolate and `ServiceInstance` in background isolate. ## FAQ ### Why the service not started automatically? @@ -35,3 +323,28 @@ Some android device manufacturers have a custom android os for example MIUI from ### Service killed by system and not respawn? Try to disable battery optimization for your app. + +### My notification icon not changed, how to solve it? + +Make sure you had created notification icons named `ic_bg_service_small` and placed in res/drawable-mdpi, res/drawable-hdpi, res/drawable-xhdpi, res/drawable-xxhdpi for PNGs file, and res/drawable-anydpi-v24 for XML (Vector) file. + +### Service not running in Release Mode + +Add `@pragma('vm:entry-point')` to the `onStart()` method. +Example: + +```dart + +@pragma('vm:entry-point') +void onStart(ServiceInstance service){ + ... +} +``` + +### Service terminated when app is in background (minimized) on iOS + +Keep in your mind, iOS doesn't have a long running service feature like Android. So, it's not possible to keep your application running when it's in background because the OS will suspend your application soon. Currently, this plugin provide onBackground method, that will be executed periodically by `Background Fetch` capability provided by iOS. It cannot be faster than 15 minutes and only alive about 15-30 seconds. + +## Discord + +Click [here](https://discord.gg/aqk6JjBm) to join to my discord channels diff --git a/android/src/main/java/id/flutter/flutter_background_service/BackgroundService.java b/android/src/main/java/id/flutter/flutter_background_service/BackgroundService.java deleted file mode 100644 index eea4bf6c..00000000 --- a/android/src/main/java/id/flutter/flutter_background_service/BackgroundService.java +++ /dev/null @@ -1,312 +0,0 @@ -package id.flutter.flutter_background_service; - -import static android.os.Build.VERSION.SDK_INT; - -import android.app.AlarmManager; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.app.Service; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Build; -import android.os.IBinder; -import android.os.PowerManager; -import android.os.PowerManager.WakeLock; -import android.util.Log; -import androidx.annotation.NonNull; -import androidx.core.app.AlarmManagerCompat; -import androidx.core.app.NotificationCompat; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.lang.UnsatisfiedLinkError; - -import io.flutter.FlutterInjector; -import io.flutter.app.FlutterApplication; -import io.flutter.embedding.engine.FlutterEngine; -import io.flutter.embedding.engine.dart.DartExecutor; -import io.flutter.embedding.engine.loader.FlutterLoader; -import io.flutter.plugin.common.JSONMethodCodec; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.MethodChannel; -import io.flutter.view.FlutterCallbackInformation; -import io.flutter.view.FlutterMain; - -public class BackgroundService extends Service implements MethodChannel.MethodCallHandler { - private static final String TAG = "BackgroundService"; - private FlutterEngine backgroundEngine; - private MethodChannel methodChannel; - private DartExecutor.DartCallback dartCallback; - private boolean isManuallyStopped = false; - - String notificationTitle = "Background Service"; - String notificationContent = "Running"; - private static final String LOCK_NAME = BackgroundService.class.getName() - + ".Lock"; - private static volatile WakeLock lockStatic = null; // notice static - - synchronized private static PowerManager.WakeLock getLock(Context context) { - if (lockStatic == null) { - PowerManager mgr = (PowerManager) context - .getSystemService(Context.POWER_SERVICE); - lockStatic = mgr.newWakeLock(PowerManager.FULL_WAKE_LOCK, - LOCK_NAME); - lockStatic.setReferenceCounted(true); - } - return (lockStatic); - } - - @Override - public IBinder onBind(Intent intent) { - return null; - } - - public static void enqueue(Context context) { - Intent intent = new Intent(context, WatchdogReceiver.class); - AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ - PendingIntent pIntent = PendingIntent.getBroadcast(context, 111, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); - AlarmManagerCompat.setAndAllowWhileIdle(manager, AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, pIntent); - return; - } - - PendingIntent pIntent = PendingIntent.getBroadcast(context, 111, intent, PendingIntent.FLAG_UPDATE_CURRENT); - AlarmManagerCompat.setAndAllowWhileIdle(manager, AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, pIntent); - } - - public void setAutoStartOnBootMode(boolean value) { - SharedPreferences pref = getSharedPreferences("id.flutter.background_service", MODE_PRIVATE); - pref.edit().putBoolean("auto_start_on_boot", value).apply(); - } - - public static boolean isAutoStartOnBootMode(Context context) { - SharedPreferences pref = context.getSharedPreferences("id.flutter.background_service", MODE_PRIVATE); - return pref.getBoolean("auto_start_on_boot", true); - } - - public void setForegroundServiceMode(boolean value) { - SharedPreferences pref = getSharedPreferences("id.flutter.background_service", MODE_PRIVATE); - pref.edit().putBoolean("is_foreground", value).apply(); - } - - public static boolean isForegroundService(Context context) { - SharedPreferences pref = context.getSharedPreferences("id.flutter.background_service", MODE_PRIVATE); - return pref.getBoolean("is_foreground", true); - } - - public void setManuallyStopped(boolean value) { - SharedPreferences pref = getSharedPreferences("id.flutter.background_service", MODE_PRIVATE); - pref.edit().putBoolean("is_manually_stopped", value).apply(); - } - - public static boolean isManuallyStopped(Context context) { - SharedPreferences pref = context.getSharedPreferences("id.flutter.background_service", MODE_PRIVATE); - return pref.getBoolean("is_manually_stopped", false); - } - - @Override - public void onCreate() { - super.onCreate(); - createNotificationChannel(); - notificationContent = "Preparing"; - updateNotificationInfo(); - } - - @Override - public void onDestroy() { - if (!isManuallyStopped) { - enqueue(this); - } else { - setManuallyStopped(true); - } - stopForeground(true); - isRunning.set(false); - - if (backgroundEngine != null) { - backgroundEngine.getServiceControlSurface().detachFromService(); - backgroundEngine.destroy(); - backgroundEngine = null; - } - - methodChannel = null; - dartCallback = null; - super.onDestroy(); - } - - private void createNotificationChannel() { - if (SDK_INT >= Build.VERSION_CODES.O) { - CharSequence name = "Background Service"; - String description = "Executing process in background"; - - int importance = NotificationManager.IMPORTANCE_LOW; - NotificationChannel channel = new NotificationChannel("FOREGROUND_DEFAULT", name, importance); - channel.setDescription(description); - - NotificationManager notificationManager = getSystemService(NotificationManager.class); - notificationManager.createNotificationChannel(channel); - } - } - - protected void updateNotificationInfo() { - if (isForegroundService(this)) { - - String packageName = getApplicationContext().getPackageName(); - Intent i = getPackageManager().getLaunchIntentForPackage(packageName); - - PendingIntent pi; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ - pi = PendingIntent.getActivity(BackgroundService.this, 99778, i, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE); - } else { - pi = PendingIntent.getActivity(BackgroundService.this, 99778, i, PendingIntent.FLAG_CANCEL_CURRENT); - } - - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, "FOREGROUND_DEFAULT") - .setSmallIcon(R.drawable.ic_bg_service_small) - .setAutoCancel(true) - .setOngoing(true) - .setContentTitle(notificationTitle) - .setContentText(notificationContent) - .setContentIntent(pi); - - startForeground(99778, mBuilder.build()); - } - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - setManuallyStopped(false); - enqueue(this); - runService(); - getLock(getApplicationContext()).acquire(); - - return START_STICKY; - } - - AtomicBoolean isRunning = new AtomicBoolean(false); - - private void runService() { - try { - Log.d(TAG, "runService"); - if (isRunning.get() || (backgroundEngine != null && !backgroundEngine.getDartExecutor().isExecutingDart())) - return; - updateNotificationInfo(); - - SharedPreferences pref = getSharedPreferences("id.flutter.background_service", MODE_PRIVATE); - long callbackHandle = pref.getLong("callback_handle", 0); - - // initialize flutter if its not initialized yet - if (!FlutterInjector.instance().flutterLoader().initialized()) { - FlutterInjector.instance().flutterLoader().startInitialization(getApplicationContext()); - } - - FlutterInjector.instance().flutterLoader().ensureInitializationComplete(getApplicationContext(), null); - FlutterCallbackInformation callback = FlutterCallbackInformation.lookupCallbackInformation(callbackHandle); - if (callback == null) { - Log.e(TAG, "callback handle not found"); - return; - } - - isRunning.set(true); - backgroundEngine = new FlutterEngine(this); - backgroundEngine.getServiceControlSurface().attachToService(BackgroundService.this, null, isForegroundService(this)); - - methodChannel = new MethodChannel(backgroundEngine.getDartExecutor().getBinaryMessenger(), "id.flutter/background_service_bg", JSONMethodCodec.INSTANCE); - methodChannel.setMethodCallHandler(this); - - dartCallback = new DartExecutor.DartCallback(getAssets(), FlutterInjector.instance().flutterLoader().findAppBundlePath(), callback); - backgroundEngine.getDartExecutor().executeDartCallback(dartCallback); - } catch (UnsatisfiedLinkError e) { - notificationContent = "Error " +e.getMessage(); - updateNotificationInfo(); - - Log.w(TAG, "UnsatisfiedLinkError: After a reboot this may happen for a short period and it is ok to ignore then!" + e.getMessage()); - } - } - - public void receiveData(JSONObject data) { - if (methodChannel != null) { - try { - methodChannel.invokeMethod("onReceiveData", data); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - @Override - public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { - String method = call.method; - - try { - if (method.equalsIgnoreCase("setNotificationInfo")) { - JSONObject arg = (JSONObject) call.arguments; - if (arg.has("title")) { - notificationTitle = arg.getString("title"); - notificationContent = arg.getString("content"); - updateNotificationInfo(); - result.success(true); - return; - } - } - - if (method.equalsIgnoreCase("setAutoStartOnBootMode")) { - JSONObject arg = (JSONObject) call.arguments; - boolean value = arg.getBoolean("value"); - setAutoStartOnBootMode(value); - result.success(true); - return; - } - - if (method.equalsIgnoreCase("setForegroundMode")) { - JSONObject arg = (JSONObject) call.arguments; - boolean value = arg.getBoolean("value"); - setForegroundServiceMode(value); - if (value) { - updateNotificationInfo(); - } else { - stopForeground(true); - } - - result.success(true); - return; - } - - if (method.equalsIgnoreCase("stopService")) { - isManuallyStopped = true; - Intent intent = new Intent(this, WatchdogReceiver.class); - PendingIntent pi; - if (SDK_INT >= Build.VERSION_CODES.S) { - pi = PendingIntent.getBroadcast(getApplicationContext(), 111, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE); - } else { - pi = PendingIntent.getBroadcast(getApplicationContext(), 111, intent, PendingIntent.FLAG_CANCEL_CURRENT); - } - - AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); - alarmManager.cancel(pi); - stopSelf(); - result.success(true); - return; - } - - if (method.equalsIgnoreCase("sendData")) { - LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this); - Intent intent = new Intent("id.flutter/background_service"); - intent.putExtra("data", ((JSONObject) call.arguments).toString()); - manager.sendBroadcast(intent); - result.success(true); - return; - } - } catch (JSONException e) { - Log.e(TAG, e.getMessage()); - e.printStackTrace(); - } - - result.notImplemented(); - } -} diff --git a/android/src/main/java/id/flutter/flutter_background_service/BootReceiver.java b/android/src/main/java/id/flutter/flutter_background_service/BootReceiver.java deleted file mode 100644 index f9581bd5..00000000 --- a/android/src/main/java/id/flutter/flutter_background_service/BootReceiver.java +++ /dev/null @@ -1,26 +0,0 @@ -package id.flutter.flutter_background_service; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; - -import androidx.core.content.ContextCompat; - -import static android.content.Context.MODE_PRIVATE; - - -public class BootReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - SharedPreferences pref = context.getSharedPreferences("id.flutter.background_service", MODE_PRIVATE); - boolean autoStart = pref.getBoolean("auto_start_on_boot",true); - if(autoStart) { - if (BackgroundService.isForegroundService(context)){ - ContextCompat.startForegroundService(context, new Intent(context, BackgroundService.class)); - } else { - context.startService(new Intent(context, BackgroundService.class)); - } - } - } -} diff --git a/android/src/main/java/id/flutter/flutter_background_service/FlutterBackgroundServicePlugin.java b/android/src/main/java/id/flutter/flutter_background_service/FlutterBackgroundServicePlugin.java deleted file mode 100644 index 6a318341..00000000 --- a/android/src/main/java/id/flutter/flutter_background_service/FlutterBackgroundServicePlugin.java +++ /dev/null @@ -1,182 +0,0 @@ -package id.flutter.flutter_background_service; - -import static android.content.Context.MODE_PRIVATE; - -import android.app.ActivityManager; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.util.Log; - -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; - -import io.flutter.embedding.engine.plugins.FlutterPlugin; -import io.flutter.embedding.engine.plugins.service.ServiceAware; -import io.flutter.embedding.engine.plugins.service.ServicePluginBinding; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.PluginRegistry.Registrar; -import io.flutter.plugin.common.JSONMethodCodec; - -/** FlutterBackgroundServicePlugin */ -public class FlutterBackgroundServicePlugin extends BroadcastReceiver implements FlutterPlugin, MethodCallHandler, ServiceAware { - private static final String TAG = "BackgroundServicePlugin"; - private static final List _instances = new ArrayList<>(); - - public FlutterBackgroundServicePlugin(){ - _instances.add(this); - } - - private MethodChannel channel; - private Context context; - private BackgroundService service; - - @Override - public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { - this.context = flutterPluginBinding.getApplicationContext(); - LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this.context); - localBroadcastManager.registerReceiver(this, new IntentFilter("id.flutter/background_service")); - - channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "id.flutter/background_service", JSONMethodCodec.INSTANCE); - channel.setMethodCallHandler(this); - } - - public static void registerWith(Registrar registrar) { - LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(registrar.context()); - final FlutterBackgroundServicePlugin plugin = new FlutterBackgroundServicePlugin(); - localBroadcastManager.registerReceiver(plugin, new IntentFilter("id.flutter/background_service")); - - final MethodChannel channel = new MethodChannel(registrar.messenger(), "id.flutter/background_service", JSONMethodCodec.INSTANCE); - channel.setMethodCallHandler(plugin); - plugin.channel = channel; - } - - private static void configure(Context context, long callbackHandleId, boolean isForeground, boolean autoStartOnBoot) { - SharedPreferences pref = context.getSharedPreferences("id.flutter.background_service", MODE_PRIVATE); - pref.edit() - .putLong("callback_handle", callbackHandleId) - .putBoolean("is_foreground", isForeground) - .putBoolean("auto_start_on_boot", autoStartOnBoot) - .apply(); - } - - private void start() { - BackgroundService.enqueue(context); - boolean isForeground = BackgroundService.isForegroundService(context); - Intent intent = new Intent(context, BackgroundService.class); - if (isForeground){ - ContextCompat.startForegroundService(context, intent); - } else { - context.startService(intent); - } - } - - - @Override - public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { - String method = call.method; - JSONObject arg = (JSONObject) call.arguments; - - try { - if ("configure".equals(method)) { - long callbackHandle = arg.getLong("handle"); - boolean isForeground = arg.getBoolean("is_foreground_mode"); - boolean autoStartOnBoot = arg.getBoolean("auto_start_on_boot"); - - configure(context, callbackHandle, isForeground, autoStartOnBoot); - if (autoStartOnBoot){ - start(); - } - - result.success(true); - return; - } - - if ("start".equals(method)){ - start(); - result.success(true); - return; - } - - if (method.equalsIgnoreCase("sendData")) { - for (FlutterBackgroundServicePlugin plugin : _instances) { - if (plugin.service != null) { - plugin.service.receiveData((JSONObject) call.arguments); - break; - } - } - - result.success(true); - return; - } - - if (method.equalsIgnoreCase("isServiceRunning")) { - ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { - if (BackgroundService.class.getName().equals(service.service.getClassName())) { - result.success(true); - return; - } - } - result.success(false); - return; - } - - result.notImplemented(); - }catch (Exception e){ - result.error("100", "Failed read arguments", null); - } - } - - @Override - public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { - channel.setMethodCallHandler(null); - - LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this.context); - localBroadcastManager.unregisterReceiver(this); - } - - @Override - public void onReceive(Context context, Intent intent) { - if (intent.getAction() == null) return; - - if (intent.getAction().equalsIgnoreCase("id.flutter/background_service")){ - String data = intent.getStringExtra("data"); - try { - JSONObject jData = new JSONObject(data); - if (channel != null){ - channel.invokeMethod("onReceiveData", jData); - } - }catch (JSONException e){ - e.printStackTrace(); - } catch (Exception e){ - e.printStackTrace(); - } - } - } - - @Override - public void onAttachedToService(@NonNull ServicePluginBinding binding) { - Log.d(TAG, "onAttachedToService"); - - this.service = (BackgroundService) binding.getService(); - } - - @Override - public void onDetachedFromService() { - this.service = null; - Log.d(TAG, "onDetachedFromService"); - } -} diff --git a/android/src/main/java/id/flutter/flutter_background_service/WatchdogReceiver.java b/android/src/main/java/id/flutter/flutter_background_service/WatchdogReceiver.java deleted file mode 100644 index e1756efb..00000000 --- a/android/src/main/java/id/flutter/flutter_background_service/WatchdogReceiver.java +++ /dev/null @@ -1,20 +0,0 @@ -package id.flutter.flutter_background_service; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -import androidx.core.content.ContextCompat; - -public class WatchdogReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - if(!BackgroundService.isManuallyStopped(context)){ - if (BackgroundService.isForegroundService(context)){ - ContextCompat.startForegroundService(context, new Intent(context, BackgroundService.class)); - } else { - context.startService(new Intent(context, BackgroundService.class)); - } - } - } -} diff --git a/android/src/main/res/drawable-anydpi-v24/ic_bg_service_small.xml b/android/src/main/res/drawable-anydpi-v24/ic_bg_service_small.xml deleted file mode 100644 index 39d15efa..00000000 --- a/android/src/main/res/drawable-anydpi-v24/ic_bg_service_small.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/bin/update.dart b/bin/update.dart deleted file mode 100644 index 55d9e3c1..00000000 --- a/bin/update.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'dart:io'; - -void main() { - final pubspec = File('pubspec.yaml'); - final version = Platform.environment['RELEASE_VERSION']; - - var contents = pubspec.readAsStringSync(); - final reg = RegExp(r'version: (\d+.\d+.\d+)'); - final match = reg.firstMatch(contents); - if (match != null) { - contents = contents.replaceRange( - match.start, - match.end, - 'version: $version', - ); - pubspec.writeAsStringSync(contents, flush: true); - } -} diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock deleted file mode 100644 index 9bfdb177..00000000 --- a/example/ios/Podfile.lock +++ /dev/null @@ -1,28 +0,0 @@ -PODS: - - device_info_plus (0.0.1): - - Flutter - - Flutter (1.0.0) - - flutter_background_service (0.0.1): - - Flutter - -DEPENDENCIES: - - device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) - - Flutter (from `Flutter`) - - flutter_background_service (from `.symlinks/plugins/flutter_background_service/ios`) - -EXTERNAL SOURCES: - device_info_plus: - :path: ".symlinks/plugins/device_info_plus/ios" - Flutter: - :path: Flutter - flutter_background_service: - :path: ".symlinks/plugins/flutter_background_service/ios" - -SPEC CHECKSUMS: - device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed - Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a - flutter_background_service: a4644870cc76287aaa6147b47107e52680b79c90 - -PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c - -COCOAPODS: 1.11.2 diff --git a/example/ios/Runner/AppDelegate.swift b/example/ios/Runner/AppDelegate.swift deleted file mode 100644 index 4e227d20..00000000 --- a/example/ios/Runner/AppDelegate.swift +++ /dev/null @@ -1,18 +0,0 @@ -import UIKit -import Flutter -import flutter_background_service - -@UIApplicationMain -@objc class AppDelegate: FlutterAppDelegate { - override func application( - _ application: UIApplication, - didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? - ) -> Bool { - GeneratedPluginRegistrant.register(with: self) - FlutterBackgroundServicePlugin.setPluginRegistrantCallback { registry in - GeneratedPluginRegistrant.register(with: registry) - } - - return super.application(application, didFinishLaunchingWithOptions: launchOptions) - } -} diff --git a/example/lib/main.dart b/example/lib/main.dart deleted file mode 100644 index c4524e87..00000000 --- a/example/lib/main.dart +++ /dev/null @@ -1,181 +0,0 @@ -import 'dart:async'; -import 'dart:io'; - -import 'package:device_info_plus/device_info_plus.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_background_service/flutter_background_service.dart'; - -Future main() async { - WidgetsFlutterBinding.ensureInitialized(); - await initializeService(); - runApp(const MyApp()); -} - -Future initializeService() async { - final service = FlutterBackgroundService(); - await service.configure( - androidConfiguration: AndroidConfiguration( - // this will executed when app is in foreground or background in separated isolate - onStart: onStart, - - // auto start service - autoStart: true, - isForegroundMode: true, - ), - iosConfiguration: IosConfiguration( - // auto start service - autoStart: true, - - // this will executed when app is in foreground in separated isolate - onForeground: onStart, - - // you have to enable background fetch capability on xcode project - onBackground: onIosBackground, - ), - ); -} - -// to ensure this executed -// run app from xcode, then from xcode menu, select Simulate Background Fetch -void onIosBackground() { - WidgetsFlutterBinding.ensureInitialized(); - print('FLUTTER BACKGROUND FETCH'); -} - -void onStart() { - WidgetsFlutterBinding.ensureInitialized(); - - final service = FlutterBackgroundService(); - service.onDataReceived.listen((event) { - if (event!["action"] == "setAsForeground") { - service.setForegroundMode(true); - return; - } - - if (event["action"] == "setAsBackground") { - service.setForegroundMode(false); - } - - if (event["action"] == "stopService") { - service.stopBackgroundService(); - } - }); - - // bring to foreground - service.setForegroundMode(true); - Timer.periodic(const Duration(seconds: 1), (timer) async { - if (!(await service.isServiceRunning())) timer.cancel(); - service.setNotificationInfo( - title: "My App Service", - content: "Updated at ${DateTime.now()}", - ); - - // test using external plugin - final deviceInfo = DeviceInfoPlugin(); - String? device; - if (Platform.isAndroid) { - final androidInfo = await deviceInfo.androidInfo; - device = androidInfo.model; - } - - if (Platform.isIOS) { - final iosInfo = await deviceInfo.iosInfo; - device = iosInfo.model; - } - - service.sendData( - { - "current_date": DateTime.now().toIso8601String(), - "device": device, - }, - ); - }); -} - -class MyApp extends StatefulWidget { - const MyApp({Key? key}) : super(key: key); - - @override - _MyAppState createState() => _MyAppState(); -} - -class _MyAppState extends State { - String text = "Stop Service"; - @override - Widget build(BuildContext context) { - return MaterialApp( - home: Scaffold( - appBar: AppBar( - title: const Text('Service App'), - ), - body: Column( - children: [ - StreamBuilder?>( - stream: FlutterBackgroundService().onDataReceived, - builder: (context, snapshot) { - if (!snapshot.hasData) { - return const Center( - child: CircularProgressIndicator(), - ); - } - - final data = snapshot.data!; - String? device = data["device"]; - DateTime? date = DateTime.tryParse(data["current_date"]); - return Column( - children: [ - Text(device ?? 'Unknown'), - Text(date.toString()), - ], - ); - }, - ), - ElevatedButton( - child: const Text("Foreground Mode"), - onPressed: () { - FlutterBackgroundService() - .sendData({"action": "setAsForeground"}); - }, - ), - ElevatedButton( - child: const Text("Background Mode"), - onPressed: () { - FlutterBackgroundService() - .sendData({"action": "setAsBackground"}); - }, - ), - ElevatedButton( - child: Text(text), - onPressed: () async { - final service = FlutterBackgroundService(); - var isRunning = await service.isServiceRunning(); - if (isRunning) { - service.sendData( - {"action": "stopService"}, - ); - } else { - service.start(); - } - - if (!isRunning) { - text = 'Stop Service'; - } else { - text = 'Start Service'; - } - setState(() {}); - }, - ), - ], - ), - floatingActionButton: FloatingActionButton( - onPressed: () { - FlutterBackgroundService().sendData({ - "hello": "world", - }); - }, - child: const Icon(Icons.play_arrow), - ), - ), - ); - } -} diff --git a/examples/simple-example-with-socketio/background_service.dart b/examples/simple-example-with-socketio/background_service.dart new file mode 100644 index 00000000..59e18514 --- /dev/null +++ b/examples/simple-example-with-socketio/background_service.dart @@ -0,0 +1,77 @@ +import 'dart:async'; +import 'dart:ui'; +import 'package:socket_io_client/socket_io_client.dart' as io; +import 'package:flutter/material.dart'; +import 'package:flutter_background_service/flutter_background_service.dart'; + +void startBackgroundService() { + final service = FlutterBackgroundService(); + service.startService(); +} + +void stopBackgroundService() { + final service = FlutterBackgroundService(); + service.invoke("stop"); +} + +Future initializeService() async { + final service = FlutterBackgroundService(); + + await service.configure( + iosConfiguration: IosConfiguration( + autoStart: true, + onForeground: onStart, + onBackground: onIosBackground, + ), + androidConfiguration: AndroidConfiguration( + autoStart: true, + onStart: onStart, + isForegroundMode: false, + autoStartOnBoot: true, + ), + ); +} + +@pragma('vm:entry-point') +Future onIosBackground(ServiceInstance service) async { + WidgetsFlutterBinding.ensureInitialized(); + DartPluginRegistrant.ensureInitialized(); + + return true; +} + +@pragma('vm:entry-point') +void onStart(ServiceInstance service) async { + + io.Socket socket = io.io('ws://10.0.2.2:5000', //specify your own socket ip and port + io.OptionBuilder() + .setTransports(['websocket']) // for Flutter or Dart VM + .enableAutoConnect() // disable auto-connection + .setExtraHeaders({'foo': 'bar'}) // optional + .build() + ); + socket.connect(); + socket.onConnect((_) { + print('Connected. Socket ID: ${socket.id}'); + // Implement your socket logic here + // For example, you can listen for events or send data + }); + + socket.onDisconnect((_) { + print('Disconnected'); + }); + socket.on("event", (data) { + //do something here + }); + service.on("stop").listen((event) { + service.stopSelf(); + debugPrint("background process is now stopped"); + }); + + service.on("start").listen((event) {}); + + Timer.periodic(const Duration(seconds: 1), (timer) { + socket.emit("clientData", "hello"); + print("service is successfully running ${DateTime.now().second}"); + }); +} diff --git a/examples/simple-example-with-socketio/main.dart b/examples/simple-example-with-socketio/main.dart new file mode 100644 index 00000000..c7851aae --- /dev/null +++ b/examples/simple-example-with-socketio/main.dart @@ -0,0 +1,7 @@ +import 'package:flutter/material.dart'; + +Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + await initializeService(); + runApp(MyApp()); +} diff --git a/ios/Classes/FlutterBackgroundServicePlugin.m b/ios/Classes/FlutterBackgroundServicePlugin.m deleted file mode 100644 index d8ecaa32..00000000 --- a/ios/Classes/FlutterBackgroundServicePlugin.m +++ /dev/null @@ -1,19 +0,0 @@ -#import "FlutterBackgroundServicePlugin.h" -#if __has_include() -#import -#else -// Support project import fallback if the generated compatibility header -// is not copied when this plugin is created as a library. -// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816 -#import "flutter_background_service-Swift.h" -#endif - -@implementation FlutterBackgroundServicePlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { - [SwiftFlutterBackgroundServicePlugin registerWithRegistrar:registrar]; -} - -+ (void)setPluginRegistrantCallback:(FlutterPluginRegistrantCallback)callback { - [SwiftFlutterBackgroundServicePlugin setPluginRegistrantCallback:callback]; -} -@end diff --git a/ios/Classes/SwiftFlutterBackgroundServicePlugin.swift b/ios/Classes/SwiftFlutterBackgroundServicePlugin.swift deleted file mode 100644 index a11c9f88..00000000 --- a/ios/Classes/SwiftFlutterBackgroundServicePlugin.swift +++ /dev/null @@ -1,214 +0,0 @@ -import Flutter -import UIKit -import AVKit -import BackgroundTasks - -public class SwiftFlutterBackgroundServicePlugin: FlutterPluginAppLifeCycleDelegate, FlutterPlugin { - - private static var flutterPluginRegistrantCallback: FlutterPluginRegistrantCallback? - - var backgroundEngine: FlutterEngine? = nil - var mainChannel: FlutterMethodChannel? = nil - var backgroundChannel: FlutterMethodChannel? = nil - - public override func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) -> Bool { - // execute callback handle - - self.beginFetch(isForeground: false) - completionHandler(.newData) - return true - } - - public override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [AnyHashable : Any] = [:]) -> Bool { - - UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum) - - if #available(iOS 13.0, *) { - registerBackgroundTasks() - } - return true - } - - @available(iOS 13.0, *) - func registerBackgroundTasks(){ - BGTaskScheduler.shared.register(forTaskWithIdentifier: "dev.flutter.background.refresh", using: nil) { task in - self.handleAppRefresh(task: task as! BGAppRefreshTask) - } - - scheduleAppRefresh() - } - - @available(iOS 13.0, *) - func scheduleAppRefresh() { - let request = BGAppRefreshTaskRequest(identifier: "dev.flutter.background.refresh") - request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60) - - do { - try BGTaskScheduler.shared.submit(request) - } catch { - print("Could not schedule app refresh: \(error)") - } - } - - @available(iOS 13.0, *) - func handleAppRefresh(task: BGAppRefreshTask){ - scheduleAppRefresh() - - var engine: FlutterEngine? = nil - let defaults = UserDefaults.standard - let callbackHandle = defaults.object(forKey: "background_callback_handle") - if callbackHandle == nil { - task.setTaskCompleted(success: false) - return - } - - if let callbackHandleID = callbackHandle as? Int64 { - let callbackHandleInfo = FlutterCallbackCache.lookupCallbackInformation(callbackHandleID) - let callbackName = callbackHandleInfo?.callbackName - let uri = callbackHandleInfo?.callbackLibraryPath - - let backgroundEngine = FlutterEngine(name: "FlutterBackgroundFetch") - let isRunning = backgroundEngine.run(withEntrypoint: callbackName, libraryURI: uri) - if (isRunning){ - - let registrantCallback = SwiftFlutterBackgroundServicePlugin.flutterPluginRegistrantCallback - registrantCallback?(backgroundEngine) - - let binaryMessenger = backgroundEngine.binaryMessenger - let backgroundChannel = FlutterMethodChannel(name: "id.flutter/background_service_bg", binaryMessenger: binaryMessenger, codec: FlutterJSONMethodCodec()) - backgroundChannel.setMethodCallHandler(self.handleBackgroundMethodCall) - } - - engine = backgroundEngine - task.setTaskCompleted(success: isRunning) - } - - task.expirationHandler = { - engine?.destroyContext() - } - } - - public static func register(with registrar: FlutterPluginRegistrar) { - let channel = FlutterMethodChannel( - name: "id.flutter/background_service", - binaryMessenger: registrar.messenger(), - codec: FlutterJSONMethodCodec()) - - let instance = SwiftFlutterBackgroundServicePlugin() - instance.mainChannel = channel - - registrar.addMethodCallDelegate(instance, channel: channel) - registrar.addApplicationDelegate(instance) - } - - public static func setPluginRegistrantCallback(_ callback: @escaping FlutterPluginRegistrantCallback) { - flutterPluginRegistrantCallback = callback - } - - private func autoStart(isForeground: Bool) { - let defaults = UserDefaults.standard - let autoStart = defaults.bool(forKey: "auto_start") - if (autoStart){ - self.beginFetch(isForeground: isForeground) - } - } - - private func handleBackgroundMethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult){ - if (call.method == "sendData"){ - if (self.mainChannel != nil){ - self.mainChannel?.invokeMethod("onReceiveData", arguments: call.arguments) - } - - result(true); - return; - } - - if (call.method == "setForegroundMode"){ - result(true); - return; - } - - if (call.method == "setNotificationInfo"){ - result(true); - return; - } - - if (call.method == "stopService"){ - self.backgroundEngine?.destroyContext(); - self.backgroundEngine = nil; - result(true); - return; - } - } - - public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - if (call.method == "configure"){ - let args = call.arguments as? Dictionary - let foregroundCallbackHandleID = args?["foreground_handle"] as? NSNumber - let backgroundCallbackHandleID = args?["background_handle"] as? NSNumber - let autoStart = args?["auto_start"] as? Bool - - let defaults = UserDefaults.standard - defaults.set(foregroundCallbackHandleID?.int64Value, forKey: "foreground_callback_handle") - defaults.set(backgroundCallbackHandleID?.int64Value, forKey: "background_callback_handle") - defaults.set(autoStart, forKey: "auto_start") - - self.autoStart(isForeground: true) - result(true) - return - } - - if (call.method == "start") { - self.beginFetch(isForeground: true) - result(true) - } - - if (call.method == "sendData"){ - if (self.backgroundChannel != nil){ - self.backgroundChannel?.invokeMethod("onReceiveData", arguments: call.arguments) - } - - result(true); - } - - if (call.method == "isServiceRunning"){ - let value = self.backgroundEngine != nil; - result(value); - return; - } - } - - // isForeground will be false if this method is executed by background fetch. - private func beginFetch(isForeground: Bool){ - if (isForeground && self.backgroundEngine != nil){ - return - } - - let defaults = UserDefaults.standard - let callbackHandle = isForeground ? defaults.object(forKey: "foreground_callback_handle") : defaults.object(forKey: "background_callback_handle") - - if let callbackHandleID = callbackHandle as? Int64 { - let callbackHandle = FlutterCallbackCache.lookupCallbackInformation(callbackHandleID) - - let callbackName = callbackHandle?.callbackName - let uri = callbackHandle?.callbackLibraryPath - - let backgroundEngine = FlutterEngine(name: "FlutterService") - let isRunning = backgroundEngine.run(withEntrypoint: callbackName, libraryURI: uri) - - if (isRunning){ - let registrantCallback = SwiftFlutterBackgroundServicePlugin.flutterPluginRegistrantCallback - registrantCallback?(backgroundEngine) - - let binaryMessenger = backgroundEngine.binaryMessenger - let backgroundChannel = FlutterMethodChannel(name: "id.flutter/background_service_bg", binaryMessenger: binaryMessenger, codec: FlutterJSONMethodCodec()) - - backgroundChannel.setMethodCallHandler(self.handleBackgroundMethodCall) - if (isForeground){ - self.backgroundEngine = backgroundEngine - self.backgroundChannel = backgroundChannel - } - } - } - } -} diff --git a/lib/flutter_background_service.dart b/lib/flutter_background_service.dart deleted file mode 100644 index 790ede8f..00000000 --- a/lib/flutter_background_service.dart +++ /dev/null @@ -1,223 +0,0 @@ -import 'dart:async'; -import 'dart:io'; -import 'dart:ui'; - -import 'package:flutter/services.dart'; - -class IosConfiguration { - /// must be a top level or static method - /// this method will be executed when app is in foreground - final Function onForeground; - - /// must be a top level or static method - /// this method will be executed by background fetch - /// make sure you don't execute long running task there because of limitations on ios - /// recommended maximum executed duration is only 15-20 seconds. - final Function onBackground; - - /// wheter service auto start after configure. - final bool autoStart; - - IosConfiguration({ - required this.onForeground, - required this.onBackground, - this.autoStart = true, - }); -} - -class AndroidConfiguration { - /// must be a top level or static method - final Function onStart; - - /// wheter service can started automatically on boot and after configure - final bool autoStart; - - /// wheter service is foreground or background mode - final bool isForegroundMode; - - final String? foregroundServiceNotificationTitle; - final String? foregroundServiceNotificationContent; - - AndroidConfiguration({ - required this.onStart, - this.autoStart = true, - required this.isForegroundMode, - this.foregroundServiceNotificationContent, - this.foregroundServiceNotificationTitle, - }); -} - -class FlutterBackgroundService { - bool _isFromInitialization = false; - bool _isRunning = false; - bool _isMainChannel = false; - static const MethodChannel _backgroundChannel = const MethodChannel( - 'id.flutter/background_service_bg', - JSONMethodCodec(), - ); - - static const MethodChannel _mainChannel = const MethodChannel( - 'id.flutter/background_service', - JSONMethodCodec(), - ); - - static FlutterBackgroundService _instance = - FlutterBackgroundService._internal().._setupBackground(); - - FlutterBackgroundService._internal(); - factory FlutterBackgroundService() => _instance; - - void _setupMain() { - _isFromInitialization = true; - _isRunning = true; - _isMainChannel = true; - _mainChannel.setMethodCallHandler(_handle); - } - - void _setupBackground() { - _isRunning = true; - _backgroundChannel.setMethodCallHandler(_handle); - } - - Future _handle(MethodCall call) async { - switch (call.method) { - case "onReceiveData": - _streamController.sink.add(call.arguments); - break; - default: - } - - return true; - } - - Future start() async { - if (!_isMainChannel) { - throw Exception( - 'This method only allowed from UI. Please call configure() first.'); - } - - final result = await _mainChannel.invokeMethod('start'); - return result ?? false; - } - - Future configure({ - required IosConfiguration iosConfiguration, - required AndroidConfiguration androidConfiguration, - }) async { - if (Platform.isAndroid) { - final CallbackHandle? handle = - PluginUtilities.getCallbackHandle(androidConfiguration.onStart); - if (handle == null) { - return false; - } - - final service = FlutterBackgroundService(); - service._setupMain(); - final result = await _mainChannel.invokeMethod( - "configure", - { - "handle": handle.toRawHandle(), - "is_foreground_mode": androidConfiguration.isForegroundMode, - "auto_start_on_boot": androidConfiguration.autoStart, - }, - ); - - return result ?? false; - } - - if (Platform.isIOS) { - final CallbackHandle? backgroundHandle = - PluginUtilities.getCallbackHandle(iosConfiguration.onBackground); - if (backgroundHandle == null) { - return false; - } - - final CallbackHandle? foregroundHandle = - PluginUtilities.getCallbackHandle(iosConfiguration.onForeground); - if (foregroundHandle == null) { - return false; - } - - final service = FlutterBackgroundService(); - service._setupMain(); - - final result = await _mainChannel.invokeMethod( - "configure", - { - "background_handle": backgroundHandle.toRawHandle(), - "foreground_handle": foregroundHandle.toRawHandle(), - "auto_start": iosConfiguration.autoStart, - }, - ); - - return result ?? false; - } - - return false; - } - - // Send data from UI to Service, or from Service to UI - void sendData(Map data) async { - if (!(await (isServiceRunning()))) { - dispose(); - return; - } - - if (_isFromInitialization) { - _mainChannel.invokeMethod("sendData", data); - return; - } - - _backgroundChannel.invokeMethod("sendData", data); - } - - // Set Foreground Notification Information - // Only available when foreground mode is true - void setNotificationInfo({String? title, String? content}) { - if (Platform.isAndroid) - _backgroundChannel.invokeMethod("setNotificationInfo", { - "title": title, - "content": content, - }); - } - - // Set Foreground Mode - // Only for Android - void setForegroundMode(bool value) { - if (Platform.isAndroid) - _backgroundChannel.invokeMethod("setForegroundMode", { - "value": value, - }); - } - - Future isServiceRunning() async { - if (_isMainChannel) { - var result = await _mainChannel.invokeMethod("isServiceRunning"); - return result ?? false; - } else { - return _isRunning; - } - } - - // StopBackgroundService from Running - void stopBackgroundService() { - _backgroundChannel.invokeMethod("stopService"); - _isRunning = false; - } - - void setAutoStartOnBootMode(bool value) { - if (Platform.isAndroid) - _backgroundChannel.invokeMethod("setAutoStartOnBootMode", { - "value": value, - }); - } - - StreamController?> _streamController = - StreamController.broadcast(); - - Stream?> get onDataReceived => _streamController.stream; - - void dispose() { - _streamController.close(); - } -} diff --git a/melos.yaml b/melos.yaml new file mode 100644 index 00000000..cf8ed5d3 --- /dev/null +++ b/melos.yaml @@ -0,0 +1,18 @@ +name: flutter_background_service +repository: https://github.com/ekasetiawans/flutter_background_service + +packages: + - packages/** + +command: + version: + # Generate commit links in package changelogs. + linkToCommits: true + # Only allow versioning to happen on main branch. + branch: master + # Additionally build a changelog at the root of the workspace. + workspaceChangelog: true + +scripts: + postclean: > + melos exec -c 6 -- "flutter clean" diff --git a/melos_flutter_background_service.iml b/melos_flutter_background_service.iml new file mode 100644 index 00000000..96815595 --- /dev/null +++ b/melos_flutter_background_service.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/packages/.DS_Store b/packages/.DS_Store new file mode 100644 index 00000000..caaaacf5 Binary files /dev/null and b/packages/.DS_Store differ diff --git a/packages/flutter_background_service/.gitignore b/packages/flutter_background_service/.gitignore new file mode 100644 index 00000000..899ae641 --- /dev/null +++ b/packages/flutter_background_service/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +.dart_tool/ + +.packages +.pub/ + +build/ +pubspec.lock +.idea/ diff --git a/.metadata b/packages/flutter_background_service/.metadata similarity index 100% rename from .metadata rename to packages/flutter_background_service/.metadata diff --git a/packages/flutter_background_service/.vscode/settings.json b/packages/flutter_background_service/.vscode/settings.json new file mode 100644 index 00000000..7f69797d --- /dev/null +++ b/packages/flutter_background_service/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dart.runPubGetOnPubspecChanges": false +} \ No newline at end of file diff --git a/packages/flutter_background_service/CHANGELOG.md b/packages/flutter_background_service/CHANGELOG.md new file mode 100644 index 00000000..9345352f --- /dev/null +++ b/packages/flutter_background_service/CHANGELOG.md @@ -0,0 +1,449 @@ +## 5.1.1 + + - Update a dependency to the latest release. + +## 5.1.0 + + - **FEAT**: remove unused imports. ([d0bbb433](https://github.com/ekasetiawans/flutter_background_service/commit/d0bbb43312877af51b5403c6fc42dd9ec2a44789)) + +## 5.0.10 + + - Update a dependency to the latest release. + +## 5.0.9 + + - Update a dependency to the latest release. + +## 5.0.8 + + - **FIX**: lints. ([7b63fca4](https://github.com/ekasetiawans/flutter_background_service/commit/7b63fca4e97941b2891570bd80701c7bb98cda23)) + +## 5.0.7 + + - **FIX**: fix crash on android 14 after starting foreground service. ([4bdc46d9](https://github.com/ekasetiawans/flutter_background_service/commit/4bdc46d951febafbcbb2b118324cddc2b30ad752)) + +## 5.0.6 + + - Update a dependency to the latest release. + +## 5.0.5 + + - **FIX**: android build error. ([8102e015](https://github.com/ekasetiawans/flutter_background_service/commit/8102e01563b967cea588a09b8a9773fc56b0dd2c)) + +## 5.0.4 + + - Update a dependency to the latest release. + +## 5.0.3 + + - Update a dependency to the latest release. + +## 5.0.2 + + - Update a dependency to the latest release. + +## 5.0.1 + + - Update a dependency to the latest release. + +## 5.0.0 + +> Note: This release has breaking changes. + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **REFACTOR**: fix sampe project dependency version. ([a83b9f62](https://github.com/ekasetiawans/flutter_background_service/commit/a83b9f62dd0d16f8bd23657ef1f36cb7d51fb0fa)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FIX**: added @pragma. ([0f90cc7d](https://github.com/ekasetiawans/flutter_background_service/commit/0f90cc7d6f1ae9b0e2ab6132151e27b88814afe1)) + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + - **FIX**: wrong dependency version. ([34e66e13](https://github.com/ekasetiawans/flutter_background_service/commit/34e66e13f04afe760d7b4087cc7052756dcb2a9c)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + - **FIX**: dependencies version. ([4e89b5e9](https://github.com/ekasetiawans/flutter_background_service/commit/4e89b5e9e5aa55074e1b10b41ea057c4b1b0bfcb)) + - **FEAT**: enhance notification icon readme. ([52e7e6ea](https://github.com/ekasetiawans/flutter_background_service/commit/52e7e6ea8bdff67924d93ce716b395bdbba2a48b)) + - **FEAT**: enhance notification icon readme. ([4d699fb0](https://github.com/ekasetiawans/flutter_background_service/commit/4d699fb03b83eae09bc3696f443a8e36092c8789)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + - **FEAT**: update dependencies. ([afc90fcc](https://github.com/ekasetiawans/flutter_background_service/commit/afc90fcc07b39954147dd24915258c96863e573e)) + - **FEAT**: managed with melos. ([2313273a](https://github.com/ekasetiawans/flutter_background_service/commit/2313273a3e728e37e2fb973ccc146841c8af48da)) + - **DOCS**: updated README.md. ([9345b16f](https://github.com/ekasetiawans/flutter_background_service/commit/9345b16f7c69e7acac1ea5d8a5985b97092a1220)) + - **DOCS**: updated README. ([f9e96ab4](https://github.com/ekasetiawans/flutter_background_service/commit/f9e96ab4978f348342703cf1de011bc59f6b9e4c)) + - **DOCS**: update README. ([5fc18ced](https://github.com/ekasetiawans/flutter_background_service/commit/5fc18ced43cc7fc1df3209eaa21ef9d424d41779)) + - **DOCS**: add documentation on configure method. ([b9612afe](https://github.com/ekasetiawans/flutter_background_service/commit/b9612afe593e766e740c69ee01a04b4f9d2ec83a)) + - **DOCS**: update FAQ. ([53215976](https://github.com/ekasetiawans/flutter_background_service/commit/532159768bc4a14701940c8166440bb1940aa1b5)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: updated README. ([2fc9ae66](https://github.com/ekasetiawans/flutter_background_service/commit/2fc9ae66f5538ab45f3690cdaee94f89b31f16e2)) + - **DOCS**: update example project for custom notification. ([d1e90d86](https://github.com/ekasetiawans/flutter_background_service/commit/d1e90d864d281747ab40170e22d91601b29927a6)) + - **DOCS**: update README. ([caf8125c](https://github.com/ekasetiawans/flutter_background_service/commit/caf8125cf557b009e06995fcc7ea8a006eba3dae)) + - **DOCS**: update README. ([88917672](https://github.com/ekasetiawans/flutter_background_service/commit/88917672c617b47691f71f964ee7ff8bd9f1d6f3)) + - **DOCS**: change method name. ([9f05e7f6](https://github.com/ekasetiawans/flutter_background_service/commit/9f05e7f6a260d8f63788cb21e8e7c2cdc91769eb)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +## 4.0.0 + +> Note: This release has breaking changes. + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **REFACTOR**: fix sampe project dependency version. ([a83b9f62](https://github.com/ekasetiawans/flutter_background_service/commit/a83b9f62dd0d16f8bd23657ef1f36cb7d51fb0fa)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FIX**: added @pragma. ([0f90cc7d](https://github.com/ekasetiawans/flutter_background_service/commit/0f90cc7d6f1ae9b0e2ab6132151e27b88814afe1)) + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + - **FIX**: wrong dependency version. ([34e66e13](https://github.com/ekasetiawans/flutter_background_service/commit/34e66e13f04afe760d7b4087cc7052756dcb2a9c)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + - **FIX**: dependencies version. ([4e89b5e9](https://github.com/ekasetiawans/flutter_background_service/commit/4e89b5e9e5aa55074e1b10b41ea057c4b1b0bfcb)) + - **FEAT**: enhance notification icon readme. ([52e7e6ea](https://github.com/ekasetiawans/flutter_background_service/commit/52e7e6ea8bdff67924d93ce716b395bdbba2a48b)) + - **FEAT**: enhance notification icon readme. ([4d699fb0](https://github.com/ekasetiawans/flutter_background_service/commit/4d699fb03b83eae09bc3696f443a8e36092c8789)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + - **FEAT**: update dependencies. ([afc90fcc](https://github.com/ekasetiawans/flutter_background_service/commit/afc90fcc07b39954147dd24915258c96863e573e)) + - **FEAT**: managed with melos. ([2313273a](https://github.com/ekasetiawans/flutter_background_service/commit/2313273a3e728e37e2fb973ccc146841c8af48da)) + - **DOCS**: updated README.md. ([9345b16f](https://github.com/ekasetiawans/flutter_background_service/commit/9345b16f7c69e7acac1ea5d8a5985b97092a1220)) + - **DOCS**: updated README. ([f9e96ab4](https://github.com/ekasetiawans/flutter_background_service/commit/f9e96ab4978f348342703cf1de011bc59f6b9e4c)) + - **DOCS**: update README. ([5fc18ced](https://github.com/ekasetiawans/flutter_background_service/commit/5fc18ced43cc7fc1df3209eaa21ef9d424d41779)) + - **DOCS**: add documentation on configure method. ([b9612afe](https://github.com/ekasetiawans/flutter_background_service/commit/b9612afe593e766e740c69ee01a04b4f9d2ec83a)) + - **DOCS**: update FAQ. ([53215976](https://github.com/ekasetiawans/flutter_background_service/commit/532159768bc4a14701940c8166440bb1940aa1b5)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: updated README. ([2fc9ae66](https://github.com/ekasetiawans/flutter_background_service/commit/2fc9ae66f5538ab45f3690cdaee94f89b31f16e2)) + - **DOCS**: update example project for custom notification. ([d1e90d86](https://github.com/ekasetiawans/flutter_background_service/commit/d1e90d864d281747ab40170e22d91601b29927a6)) + - **DOCS**: update README. ([caf8125c](https://github.com/ekasetiawans/flutter_background_service/commit/caf8125cf557b009e06995fcc7ea8a006eba3dae)) + - **DOCS**: update README. ([88917672](https://github.com/ekasetiawans/flutter_background_service/commit/88917672c617b47691f71f964ee7ff8bd9f1d6f3)) + - **DOCS**: change method name. ([9f05e7f6](https://github.com/ekasetiawans/flutter_background_service/commit/9f05e7f6a260d8f63788cb21e8e7c2cdc91769eb)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +## 3.0.2 + + - Update a dependency to the latest release. + +## 3.0.1 + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + +## 3.0.0 + +> Note: This release has breaking changes. + + - **FEAT**: enhance notification icon readme. ([52e7e6ea](https://github.com/ekasetiawans/flutter_background_service/commit/52e7e6ea8bdff67924d93ce716b395bdbba2a48b)) + - **FEAT**: enhance notification icon readme. ([4d699fb0](https://github.com/ekasetiawans/flutter_background_service/commit/4d699fb03b83eae09bc3696f443a8e36092c8789)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + +## 2.4.6 + + - **DOCS**: updated README.md. ([9345b16f](https://github.com/ekasetiawans/flutter_background_service/commit/9345b16f7c69e7acac1ea5d8a5985b97092a1220)) + +## 2.4.5 + + - **DOCS**: updated README. ([f9e96ab4](https://github.com/ekasetiawans/flutter_background_service/commit/f9e96ab4978f348342703cf1de011bc59f6b9e4c)) + +## 2.4.4 + + - Update a dependency to the latest release. + +## 2.4.3 + + - **DOCS**: update README. ([5fc18ced](https://github.com/ekasetiawans/flutter_background_service/commit/5fc18ced43cc7fc1df3209eaa21ef9d424d41779)) + +## 2.4.2 + + - **DOCS**: add documentation on configure method. ([b9612afe](https://github.com/ekasetiawans/flutter_background_service/commit/b9612afe593e766e740c69ee01a04b4f9d2ec83a)) + +## 2.4.1 + + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + +## 2.4.0 + + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + +## 2.3.10 + + - Update a dependency to the latest release. + +## 2.3.9 + + - **FIX**: added @pragma. ([0f90cc7d](https://github.com/ekasetiawans/flutter_background_service/commit/0f90cc7d6f1ae9b0e2ab6132151e27b88814afe1)) + - **DOCS**: update FAQ. ([53215976](https://github.com/ekasetiawans/flutter_background_service/commit/532159768bc4a14701940c8166440bb1940aa1b5)) + +## 2.3.8 + + - Update a dependency to the latest release. + +## 2.3.7 + + - Update a dependency to the latest release. + +## 2.3.6 + + - Update a dependency to the latest release. + +## 2.3.5 + + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + +## 2.3.4 + + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + +## 2.3.3 + + - **FIX**: wrong dependency version. ([34e66e13](https://github.com/ekasetiawans/flutter_background_service/commit/34e66e13f04afe760d7b4087cc7052756dcb2a9c)) + +## 2.3.2 + + - **DOCS**: updated README. ([2fc9ae66](https://github.com/ekasetiawans/flutter_background_service/commit/2fc9ae66f5538ab45f3690cdaee94f89b31f16e2)) + - **DOCS**: updated README. ([3885e301](https://github.com/ekasetiawans/flutter_background_service/commit/3885e3017729a557b0b0b7ccdb968692ba7c8a52)) + +## 2.3.0 + + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + +## 2.2.4 + + - **DOCS**: update example project for custom notification. ([d1e90d86](https://github.com/ekasetiawans/flutter_background_service/commit/d1e90d864d281747ab40170e22d91601b29927a6)) + +## 2.2.3 + + - Update a dependency to the latest release. + +## 2.2.2 + + - Update a dependency to the latest release. + +## 2.2.1 + + - Update a dependency to the latest release. + +## 2.2.0 + + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + +## 2.1.3 + + - Update a dependency to the latest release. + +## 2.1.2 + + - Update a dependency to the latest release. + +## 2.1.1 + + - Update a dependency to the latest release. + +## 2.1.0 + + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + +## 2.0.0 + + - Graduate package to a stable release. See pre-releases prior to this version for changelog entries. + +## 2.0.0-dev.3 + + - **REFACTOR**: fix sampe project dependency version. ([a83b9f62](https://github.com/ekasetiawans/flutter_background_service/commit/a83b9f62dd0d16f8bd23657ef1f36cb7d51fb0fa)) + +## 2.0.0-dev.2 + + - Update a dependency to the latest release. + +## 2.0.0-dev.1 + + - **DOCS**: update README. ([caf8125c](https://github.com/ekasetiawans/flutter_background_service/commit/caf8125cf557b009e06995fcc7ea8a006eba3dae)) + +## 2.0.0-dev.0 + +> Note: This release has breaking changes. + + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +## 1.0.4 + + - **DOCS**: update README. ([88917672](https://github.com/ekasetiawans/flutter_background_service/commit/88917672c617b47691f71f964ee7ff8bd9f1d6f3)) + +## 1.0.3 + + - Update a dependency to the latest release. + +## 1.0.2 + + - Update a dependency to the latest release. + +## 1.0.1 + + - **DOCS**: change method name. ([9f05e7f6](https://github.com/ekasetiawans/flutter_background_service/commit/9f05e7f6a260d8f63788cb21e8e7c2cdc91769eb)) + +## 0.2.8+5 + + - Update a dependency to the latest release. + +## 0.2.8+4 + + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + +## 0.2.8+3 + + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + +## 0.2.8+2 + + - Update a dependency to the latest release. + +## 0.2.8+1 + + - **FIX**: dependencies version. + +## 0.2.8 + + - **FEAT**: update dependencies. + +## 0.2.7 + + - **REFACTOR**: initialize melos. + - **FEAT**: managed with melos. + +## 0.2.6 +* FIX: (Android) flutter initialization +## 0.2.5 +* FIX: (iOS) using other plugins +## 0.2.4 +* FIX: (Android) run service background when charger not connected and screen lock (#92) +## 0.2.3 +* ADDED: Using `BGTaskScheduler` on iOS 13. See readme for configuration. +## 0.2.2 +* ADDED: `autoStart` to `IosConfiguration` +## 0.2.1 +* UPDATE README +* UPDATE: Flutter Version Constraint +## 0.2.0+1 +* UPDATE README + +## 0.2.0 +* [BREAKING]: FlutterBackgroundService.initialize renamed to FlutterBackgroundService.configure +* [BREAKING]: use FlutterBackgroundService.start to start or restart after you call stopService. +* [ADDED]: IOS Background fetch is now supported you have to enable background fetch from xcode. +## 0.1.7 + +* Fix : cannot start service on android 12 +* Fix : not started on boot completed +## 0.1.6 + +* Android 12 Compatibility Changes +## 0.1.5 + +* Rollback foreground notification importance +## 0.1.4 + +* fixes UnsatisfiedLinkError when running as foreground service with autostart #32 +## 0.1.3 + +* Fix notification not showing on android 7 and prior (Issue #26) +## 0.1.2 + +* Open app from notification (Issue #30) +## 0.1.1 + +* Fix #29 (DartVM not terminated when service stop) + +## 0.1.0 + +* Bump flutter 2 + +## 0.1.0-nullsafety.2 + +* Fix #23 + +## 0.1.0-nullsafety.1 + +* Added isServiceRunning on iOS (issue #19) + +## 0.1.0-nullsafety.0 + +* Added support to nullsafety + +## 0.0.1+18 + +* Added stopService Method(Currently Works on Android Only). + +## 0.0.1+17 + +* Add preference autoStart on Boot, default is true. + +## 0.0.1+16 + +* Set Foreground Mode to false will remove notification. BugFix #4. + +## 0.0.1+15 + +* Add ability to change Background or Foreground mode (Android Only) + +## 0.0.1+14 + +* Bugfix BootReceiver + +## 0.0.1+13 + +* Update example for iOS support. + +## 0.0.1+12 + +* Start service immediately after initialize + +## 0.0.1+11 + +* iOS + +## 0.0.1+10 + +* bug fix + +## 0.0.1+9 + +* bug fix + +## 0.0.1+8 + +* bug fix + +## 0.0.1+7 + +* Add ability to send data from UI to Service + +## 0.0.1+6 + +* Improve stability + +## 0.0.1+5 + +* Add ability to send data from service to UI + +## 0.0.1+4 + +* Update README + +## 0.0.1+3 + +* Add ability to change notification info (Android foreground service) + +## 0.0.1+2 + +* Fix android missing plugin implementation + +## 0.0.1+1 + +* Fix android build + +## 0.0.1 + +* TODO: Describe initial release. \ No newline at end of file diff --git a/packages/flutter_background_service/LICENSE b/packages/flutter_background_service/LICENSE new file mode 100644 index 00000000..0b8db9ec --- /dev/null +++ b/packages/flutter_background_service/LICENSE @@ -0,0 +1,7 @@ +Copyright 2022 Eka Setiawan Saputra + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/flutter_background_service/README.md b/packages/flutter_background_service/README.md new file mode 100644 index 00000000..eafbf89b --- /dev/null +++ b/packages/flutter_background_service/README.md @@ -0,0 +1,331 @@ +A flutter plugin for execute dart code in background. + +## Support me to maintain this plugin continously with a cup of coffee. + +[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/ekasetiawans) + +## Android + +- To change notification icon, just add drawable icon with name `ic_bg_service_small`. + +> **WARNING**: +> +> Please make sure your project already use the version of gradle tools below: +> - in android/build.gradle ```classpath 'com.android.tools.build:gradle:7.4.2'``` +> - in android/build.gradle ```ext.kotlin_version = '1.8.10'``` +> - in android/gradle/wrapper/gradle-wrapper.properties ```distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip``` + +### Configuration required for Foreground Services on Android 14 (SDK 34) + +Applications that target SDK 34 and use foreground services need to include some additional configuration to declare the type of foreground service they use: + +* Determine the type of foreground service your app requires by consulting [the documentation](https://developer.android.com/about/versions/14/changes/fgs-types-required) + +* Add the corresponding permission to your `android/app/src/main/AndroidManifest.xml` file: + +```xml + + ... + + + + + + + + + + + + ... + ... + + +``` + +> **WARNING**: +> * YOU MUST MAKE SURE ANY REQUIRED PERMISSIONS TO BE GRANTED BEFORE YOU START THE SERVICE + + +### Using custom notification for Foreground Service +You can make your own custom notification for foreground service. It can give you more power to make notifications more attractive to users, for example adding progressbars, buttons, actions, etc. The example below is using [flutter_local_notifications](https://pub.dev/packages/flutter_local_notifications) plugin, but you can use any other notification plugin. You can follow how to make it below: + +- Notification Channel +```dart + +Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + await initializeService(); + + runApp(MyApp()); +} + +// this will be used as notification channel id +const notificationChannelId = 'my_foreground'; + +// this will be used for notification id, So you can update your custom notification with this id. +const notificationId = 888; + +Future initializeService() async { + final service = FlutterBackgroundService(); + + const AndroidNotificationChannel channel = AndroidNotificationChannel( + notificationChannelId, // id + 'MY FOREGROUND SERVICE', // title + description: + 'This channel is used for important notifications.', // description + importance: Importance.low, // importance must be at low or higher level + ); + + final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = + FlutterLocalNotificationsPlugin(); + + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + ?.createNotificationChannel(channel); + + await service.configure( + androidConfiguration: AndroidConfiguration( + // this will be executed when app is in foreground or background in separated isolate + onStart: onStart, + + // auto start service + autoStart: true, + isForegroundMode: true, + + notificationChannelId: notificationChannelId, // this must match with notification channel you created above. + initialNotificationTitle: 'AWESOME SERVICE', + initialNotificationContent: 'Initializing', + foregroundServiceNotificationId: notificationId, + ), + ... +``` + +- Update notification info + +```dart + +Future onStart(ServiceInstance service) async { + // Only available for flutter 3.0.0 and later + DartPluginRegistrant.ensureInitialized(); + + final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = + FlutterLocalNotificationsPlugin(); + + // bring to foreground + Timer.periodic(const Duration(seconds: 1), (timer) async { + if (service is AndroidServiceInstance) { + if (await service.isForegroundService()) { + flutterLocalNotificationsPlugin.show( + notificationId, + 'COOL SERVICE', + 'Awesome ${DateTime.now()}', + const NotificationDetails( + android: AndroidNotificationDetails( + notificationChannelId, + 'MY FOREGROUND SERVICE', + icon: 'ic_bg_service_small', + ongoing: true, + ), + ), + ); + } + } + }); +} +``` + + +### Using Background Service Even when The Application Is Closed + +You can use this feature in order to execute code in background. +Very useful to fetch realtime data from a server and push notifications. + +> **Must Know**: +> * ``` isForegroundMode: false ``` : The background mode requires running in release mode and requires disabling battery optimization so that the service stays up when the user closes the application. +> * ``` isForegroundMode: true ``` : Displays a silent notification when used according to [Android's Policy](https://developer.android.com/develop/background-work/services) + + +- Simple implementation using Socket.io +```dart +import 'dart:async'; +import 'dart:ui'; +import 'package:socket_io_client/socket_io_client.dart' as io; +import 'package:flutter/material.dart'; +import 'package:flutter_background_service/flutter_background_service.dart'; + +Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + await initializeService(); + + runApp(MyApp()); +} + +void startBackgroundService() { + final service = FlutterBackgroundService(); + service.startService(); +} + +void stopBackgroundService() { + final service = FlutterBackgroundService(); + service.invoke("stop"); +} + +Future initializeService() async { + final service = FlutterBackgroundService(); + + await service.configure( + iosConfiguration: IosConfiguration( + autoStart: true, + onForeground: onStart, + onBackground: onIosBackground, + ), + androidConfiguration: AndroidConfiguration( + autoStart: true, + onStart: onStart, + isForegroundMode: false, + autoStartOnBoot: true, + ), + ); +} + +@pragma('vm:entry-point') +Future onIosBackground(ServiceInstance service) async { + WidgetsFlutterBinding.ensureInitialized(); + DartPluginRegistrant.ensureInitialized(); + + return true; +} + +@pragma('vm:entry-point') +void onStart(ServiceInstance service) async { + final socket = io.io("your-server-url", { + 'transports': ['websocket'], + 'autoConnect': true, + }); + socket.onConnect((_) { + print('Connected. Socket ID: ${socket.id}'); + // Implement your socket logic here + // For example, you can listen for events or send data + }); + + socket.onDisconnect((_) { + print('Disconnected'); + }); + socket.on("event-name", (data) { + //do something here like pushing a notification + }); + service.on("stop").listen((event) { + service.stopSelf(); + print("background process is now stopped"); + }); + + service.on("start").listen((event) {}); + + Timer.periodic(const Duration(seconds: 1), (timer) { + socket.emit("event-name", "your-message"); + print("service is successfully running ${DateTime.now().second}"); + }); +} +``` + +## iOS + +- Enable `background_fetch` capability in xcode (optional), if you wish ios to execute `IosConfiguration.onBackground` callback. + +- For iOS 13 and Later (using `BGTaskScheduler`), insert lines below into your ios/Runner/Info.plist + +```plist +BGTaskSchedulerPermittedIdentifiers + + dev.flutter.background.refresh + +``` + +- You can also using your own custom identifier +In `ios/Runner/AppDelegate.swift` add line below + +```swift +import UIKit +import Flutter +import flutter_background_service_ios // add this + +@UIApplicationMain +@objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + /// Add this line + SwiftFlutterBackgroundServicePlugin.taskIdentifier = "your.custom.task.identifier" + + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +} +``` + +## Usage + +- Call `FlutterBackgroundService.configure()` to configure handler that will be executed by the Service. + +> It's highly recommended to call this method in `main()` method to ensure the callback handler updated. + +- Call `FlutterBackgroundService.start` to start the Service if `autoStart` is not enabled. + +- Since the Service using Isolates, You won't be able to share reference between UI and Service. You can communicate between UI and Service using `invoke()` and `on(String method)`. + +## Migration + +- `sendData()` renamed to `invoke(String method)` +- `onDataReceived()` renamed to `on(String method)` +- Now you have to use `ServiceInstance` object inside `onStart` method instead of creating a new `FlutterBackgroundService` object. See the example project. +- Only use `FlutterBackgroundService` class in UI Isolate and `ServiceInstance` in background isolate. +## FAQ + +### Why the service not started automatically? + +Some android device manufacturers have a custom android os for example MIUI from Xiaomi. You have to deal with that policy. + +### Service killed by system and not respawn? + +Try to disable battery optimization for your app. + +### My notification icon not changed, how to solve it? + +Make sure you had created notification icons named `ic_bg_service_small` and placed in res/drawable-mdpi, res/drawable-hdpi, res/drawable-xhdpi, res/drawable-xxhdpi for PNGs file, and res/drawable-anydpi-v24 for XML (Vector) file. + +### Service not running in Release Mode + +Add `@pragma('vm:entry-point')` to the `onStart()` method. +Example: + +```dart + +@pragma('vm:entry-point') +void onStart(ServiceInstance service){ + ... +} +``` + +### Service terminated when app is in background (minimized) on iOS + +Keep in your mind, iOS doesn't have a long running service feature like Android. So, it's not possible to keep your application running when it's in background because the OS will suspend your application soon. Currently, this plugin provide onBackground method, that will be executed periodically by `Background Fetch` capability provided by iOS. It cannot be faster than 15 minutes and only alive about 15-30 seconds. + +## Discord + +Click [here](https://discord.gg/aqk6JjBm) to join to my discord channels diff --git a/example/.gitignore b/packages/flutter_background_service/example/.gitignore similarity index 100% rename from example/.gitignore rename to packages/flutter_background_service/example/.gitignore diff --git a/example/.metadata b/packages/flutter_background_service/example/.metadata similarity index 100% rename from example/.metadata rename to packages/flutter_background_service/example/.metadata diff --git a/example/.vscode/launch.json b/packages/flutter_background_service/example/.vscode/launch.json similarity index 100% rename from example/.vscode/launch.json rename to packages/flutter_background_service/example/.vscode/launch.json diff --git a/packages/flutter_background_service/example/CHANGELOG.md b/packages/flutter_background_service/example/CHANGELOG.md new file mode 100644 index 00000000..e03ab6fd --- /dev/null +++ b/packages/flutter_background_service/example/CHANGELOG.md @@ -0,0 +1,11 @@ +## 2.0.0 + +> Note: This release has breaking changes. + + - **REFACTOR**: fix sampe project dependency version. ([a83b9f62](https://github.com/ekasetiawans/flutter_background_service/commit/a83b9f62dd0d16f8bd23657ef1f36cb7d51fb0fa)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + - **FEAT**: managed with melos. ([2313273a](https://github.com/ekasetiawans/flutter_background_service/commit/2313273a3e728e37e2fb973ccc146841c8af48da)) + - **DOCS**: change method name. ([9f05e7f6](https://github.com/ekasetiawans/flutter_background_service/commit/9f05e7f6a260d8f63788cb21e8e7c2cdc91769eb)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + diff --git a/example/README.md b/packages/flutter_background_service/example/README.md similarity index 100% rename from example/README.md rename to packages/flutter_background_service/example/README.md diff --git a/example/analysis_options.yaml b/packages/flutter_background_service/example/analysis_options.yaml similarity index 100% rename from example/analysis_options.yaml rename to packages/flutter_background_service/example/analysis_options.yaml diff --git a/example/android/.gitignore b/packages/flutter_background_service/example/android/.gitignore similarity index 100% rename from example/android/.gitignore rename to packages/flutter_background_service/example/android/.gitignore diff --git a/example/android/app/build.gradle b/packages/flutter_background_service/example/android/app/build.gradle similarity index 88% rename from example/android/app/build.gradle rename to packages/flutter_background_service/example/android/app/build.gradle index 02b8d953..82f5bbce 100644 --- a/example/android/app/build.gradle +++ b/packages/flutter_background_service/example/android/app/build.gradle @@ -26,16 +26,16 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion flutter.compileSdkVersion + compileSdkVersion 34 - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - kotlinOptions { - jvmTarget = '1.8' - } +// compileOptions { +// sourceCompatibility JavaVersion.VERSION_1_8 +// targetCompatibility JavaVersion.VERSION_1_8 +// } +// +// kotlinOptions { +// jvmTarget = '1.8' +// } sourceSets { main.java.srcDirs += 'src/main/kotlin' diff --git a/example/android/app/src/debug/AndroidManifest.xml b/packages/flutter_background_service/example/android/app/src/debug/AndroidManifest.xml similarity index 100% rename from example/android/app/src/debug/AndroidManifest.xml rename to packages/flutter_background_service/example/android/app/src/debug/AndroidManifest.xml diff --git a/example/android/app/src/main/AndroidManifest.xml b/packages/flutter_background_service/example/android/app/src/main/AndroidManifest.xml similarity index 80% rename from example/android/app/src/main/AndroidManifest.xml rename to packages/flutter_background_service/example/android/app/src/main/AndroidManifest.xml index e60bce76..8ed136b4 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/packages/flutter_background_service/example/android/app/src/main/AndroidManifest.xml @@ -1,9 +1,19 @@ + + + + + + + CFBundleVersion 1.0 MinimumOSVersion - 9.0 + 11.0 diff --git a/example/ios/Flutter/Debug.xcconfig b/packages/flutter_background_service/example/ios/Flutter/Debug.xcconfig similarity index 100% rename from example/ios/Flutter/Debug.xcconfig rename to packages/flutter_background_service/example/ios/Flutter/Debug.xcconfig diff --git a/example/ios/Flutter/Release.xcconfig b/packages/flutter_background_service/example/ios/Flutter/Release.xcconfig similarity index 100% rename from example/ios/Flutter/Release.xcconfig rename to packages/flutter_background_service/example/ios/Flutter/Release.xcconfig diff --git a/example/ios/Podfile b/packages/flutter_background_service/example/ios/Podfile similarity index 98% rename from example/ios/Podfile rename to packages/flutter_background_service/example/ios/Podfile index 1e8c3c90..88359b22 100644 --- a/example/ios/Podfile +++ b/packages/flutter_background_service/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '9.0' +# platform :ios, '11.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/packages/flutter_background_service/example/ios/Podfile.lock b/packages/flutter_background_service/example/ios/Podfile.lock new file mode 100644 index 00000000..cd4f64d9 --- /dev/null +++ b/packages/flutter_background_service/example/ios/Podfile.lock @@ -0,0 +1,40 @@ +PODS: + - device_info_plus (0.0.1): + - Flutter + - Flutter (1.0.0) + - flutter_background_service_ios (0.0.3): + - Flutter + - flutter_local_notifications (0.0.1): + - Flutter + - shared_preferences_ios (0.0.1): + - Flutter + +DEPENDENCIES: + - device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) + - Flutter (from `Flutter`) + - flutter_background_service_ios (from `.symlinks/plugins/flutter_background_service_ios/ios`) + - flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`) + - shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`) + +EXTERNAL SOURCES: + device_info_plus: + :path: ".symlinks/plugins/device_info_plus/ios" + Flutter: + :path: Flutter + flutter_background_service_ios: + :path: ".symlinks/plugins/flutter_background_service_ios/ios" + flutter_local_notifications: + :path: ".symlinks/plugins/flutter_local_notifications/ios" + shared_preferences_ios: + :path: ".symlinks/plugins/shared_preferences_ios/ios" + +SPEC CHECKSUMS: + device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed + Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 + flutter_background_service_ios: e30e0d3ee69e4cee66272d0c78eacd48c2e94aac + flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743 + shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad + +PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3 + +COCOAPODS: 1.11.3 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/packages/flutter_background_service/example/ios/Runner.xcodeproj/project.pbxproj similarity index 99% rename from example/ios/Runner.xcodeproj/project.pbxproj rename to packages/flutter_background_service/example/ios/Runner.xcodeproj/project.pbxproj index 6ef74a9b..c1b7981c 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/flutter_background_service/example/ios/Runner.xcodeproj/project.pbxproj @@ -340,7 +340,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -418,7 +418,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -467,7 +467,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/packages/flutter_background_service/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to packages/flutter_background_service/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/flutter_background_service/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/flutter_background_service/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/packages/flutter_background_service/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to packages/flutter_background_service/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/flutter_background_service/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme similarity index 100% rename from example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme rename to packages/flutter_background_service/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme diff --git a/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/packages/flutter_background_service/example/ios/Runner.xcworkspace/contents.xcworkspacedata similarity index 100% rename from example/ios/Runner.xcworkspace/contents.xcworkspacedata rename to packages/flutter_background_service/example/ios/Runner.xcworkspace/contents.xcworkspacedata diff --git a/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/flutter_background_service/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist similarity index 100% rename from example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename to packages/flutter_background_service/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/packages/flutter_background_service/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings similarity index 100% rename from example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings rename to packages/flutter_background_service/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/packages/flutter_background_service/example/ios/Runner/AppDelegate.swift b/packages/flutter_background_service/example/ios/Runner/AppDelegate.swift new file mode 100644 index 00000000..4d959f69 --- /dev/null +++ b/packages/flutter_background_service/example/ios/Runner/AppDelegate.swift @@ -0,0 +1,15 @@ +import UIKit +import Flutter +import flutter_background_service_ios + +@UIApplicationMain +@objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + SwiftFlutterBackgroundServicePlugin.taskIdentifier = "dev.flutter.background.refresh" + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +} diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json similarity index 100% rename from example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png similarity index 100% rename from example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/packages/flutter_background_service/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md similarity index 100% rename from example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md rename to packages/flutter_background_service/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md diff --git a/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/packages/flutter_background_service/example/ios/Runner/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from example/ios/Runner/Base.lproj/LaunchScreen.storyboard rename to packages/flutter_background_service/example/ios/Runner/Base.lproj/LaunchScreen.storyboard diff --git a/example/ios/Runner/Base.lproj/Main.storyboard b/packages/flutter_background_service/example/ios/Runner/Base.lproj/Main.storyboard similarity index 100% rename from example/ios/Runner/Base.lproj/Main.storyboard rename to packages/flutter_background_service/example/ios/Runner/Base.lproj/Main.storyboard diff --git a/example/ios/Runner/Info.plist b/packages/flutter_background_service/example/ios/Runner/Info.plist similarity index 96% rename from example/ios/Runner/Info.plist rename to packages/flutter_background_service/example/ios/Runner/Info.plist index 3ffe322c..acb06ad6 100644 --- a/example/ios/Runner/Info.plist +++ b/packages/flutter_background_service/example/ios/Runner/Info.plist @@ -51,5 +51,7 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + diff --git a/example/ios/Runner/Runner-Bridging-Header.h b/packages/flutter_background_service/example/ios/Runner/Runner-Bridging-Header.h similarity index 100% rename from example/ios/Runner/Runner-Bridging-Header.h rename to packages/flutter_background_service/example/ios/Runner/Runner-Bridging-Header.h diff --git a/packages/flutter_background_service/example/lib/main.dart b/packages/flutter_background_service/example/lib/main.dart new file mode 100644 index 00000000..94d7b164 --- /dev/null +++ b/packages/flutter_background_service/example/lib/main.dart @@ -0,0 +1,284 @@ +import 'dart:async'; +import 'dart:io'; +import 'dart:ui'; + +import 'package:device_info_plus/device_info_plus.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_background_service/flutter_background_service.dart'; +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + await initializeService(); + runApp(const MyApp()); +} + +Future initializeService() async { + final service = FlutterBackgroundService(); + + /// OPTIONAL, using custom notification channel id + const AndroidNotificationChannel channel = AndroidNotificationChannel( + 'my_foreground', // id + 'MY FOREGROUND SERVICE', // title + description: + 'This channel is used for important notifications.', // description + importance: Importance.low, // importance must be at low or higher level + ); + + final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = + FlutterLocalNotificationsPlugin(); + + if (Platform.isIOS || Platform.isAndroid) { + await flutterLocalNotificationsPlugin.initialize( + const InitializationSettings( + iOS: DarwinInitializationSettings(), + android: AndroidInitializationSettings('ic_bg_service_small'), + ), + ); + } + + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + ?.createNotificationChannel(channel); + + await service.configure( + androidConfiguration: AndroidConfiguration( + // this will be executed when app is in foreground or background in separated isolate + onStart: onStart, + + // auto start service + autoStart: true, + isForegroundMode: true, + + notificationChannelId: 'my_foreground', + initialNotificationTitle: 'AWESOME SERVICE', + initialNotificationContent: 'Initializing', + foregroundServiceNotificationId: 888, + foregroundServiceTypes: [AndroidForegroundType.location], + ), + iosConfiguration: IosConfiguration( + // auto start service + autoStart: true, + + // this will be executed when app is in foreground in separated isolate + onForeground: onStart, + + // you have to enable background fetch capability on xcode project + onBackground: onIosBackground, + ), + ); +} + +// to ensure this is executed +// run app from xcode, then from xcode menu, select Simulate Background Fetch + +@pragma('vm:entry-point') +Future onIosBackground(ServiceInstance service) async { + WidgetsFlutterBinding.ensureInitialized(); + DartPluginRegistrant.ensureInitialized(); + + SharedPreferences preferences = await SharedPreferences.getInstance(); + await preferences.reload(); + final log = preferences.getStringList('log') ?? []; + log.add(DateTime.now().toIso8601String()); + await preferences.setStringList('log', log); + + return true; +} + +@pragma('vm:entry-point') +void onStart(ServiceInstance service) async { + // Only available for flutter 3.0.0 and later + DartPluginRegistrant.ensureInitialized(); + + // For flutter prior to version 3.0.0 + // We have to register the plugin manually + + SharedPreferences preferences = await SharedPreferences.getInstance(); + await preferences.setString("hello", "world"); + + /// OPTIONAL when use custom notification + final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = + FlutterLocalNotificationsPlugin(); + + if (service is AndroidServiceInstance) { + service.on('setAsForeground').listen((event) { + service.setAsForegroundService(); + }); + + service.on('setAsBackground').listen((event) { + service.setAsBackgroundService(); + }); + } + + service.on('stopService').listen((event) { + service.stopSelf(); + }); + + // bring to foreground + Timer.periodic(const Duration(seconds: 1), (timer) async { + if (service is AndroidServiceInstance) { + if (await service.isForegroundService()) { + /// OPTIONAL for use custom notification + /// the notification id must be equals with AndroidConfiguration when you call configure() method. + flutterLocalNotificationsPlugin.show( + 888, + 'COOL SERVICE', + 'Awesome ${DateTime.now()}', + const NotificationDetails( + android: AndroidNotificationDetails( + 'my_foreground', + 'MY FOREGROUND SERVICE', + icon: 'ic_bg_service_small', + ongoing: true, + ), + ), + ); + + // if you don't using custom notification, uncomment this + service.setForegroundNotificationInfo( + title: "My App Service", + content: "Updated at ${DateTime.now()}", + ); + } + } + + /// you can see this log in logcat + debugPrint('FLUTTER BACKGROUND SERVICE: ${DateTime.now()}'); + + // test using external plugin + final deviceInfo = DeviceInfoPlugin(); + String? device; + if (Platform.isAndroid) { + final androidInfo = await deviceInfo.androidInfo; + device = androidInfo.model; + } else if (Platform.isIOS) { + final iosInfo = await deviceInfo.iosInfo; + device = iosInfo.model; + } + + service.invoke( + 'update', + { + "current_date": DateTime.now().toIso8601String(), + "device": device, + }, + ); + }); +} + +class MyApp extends StatefulWidget { + const MyApp({Key? key}) : super(key: key); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + String text = "Stop Service"; + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('Service App'), + ), + body: Column( + children: [ + StreamBuilder?>( + stream: FlutterBackgroundService().on('update'), + builder: (context, snapshot) { + if (!snapshot.hasData) { + return const Center( + child: CircularProgressIndicator(), + ); + } + + final data = snapshot.data!; + String? device = data["device"]; + DateTime? date = DateTime.tryParse(data["current_date"]); + return Column( + children: [ + Text(device ?? 'Unknown'), + Text(date.toString()), + ], + ); + }, + ), + ElevatedButton( + child: const Text("Foreground Mode"), + onPressed: () => + FlutterBackgroundService().invoke("setAsForeground"), + ), + ElevatedButton( + child: const Text("Background Mode"), + onPressed: () => + FlutterBackgroundService().invoke("setAsBackground"), + ), + ElevatedButton( + child: Text(text), + onPressed: () async { + final service = FlutterBackgroundService(); + var isRunning = await service.isRunning(); + isRunning + ? service.invoke("stopService") + : service.startService(); + + setState(() { + text = isRunning ? 'Start Service' : 'Stop Service'; + }); + }, + ), + const Expanded( + child: LogView(), + ), + ], + ), + ), + ); + } +} + +class LogView extends StatefulWidget { + const LogView({Key? key}) : super(key: key); + + @override + State createState() => _LogViewState(); +} + +class _LogViewState extends State { + late final Timer timer; + List logs = []; + + @override + void initState() { + super.initState(); + timer = Timer.periodic(const Duration(seconds: 1), (timer) async { + final SharedPreferences sp = await SharedPreferences.getInstance(); + await sp.reload(); + logs = sp.getStringList('log') ?? []; + if (mounted) { + setState(() {}); + } + }); + } + + @override + void dispose() { + timer.cancel(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return ListView.builder( + itemCount: logs.length, + itemBuilder: (context, index) { + final log = logs.elementAt(index); + return Text(log); + }, + ); + } +} diff --git a/example/pubspec.yaml b/packages/flutter_background_service/example/pubspec.yaml similarity index 92% rename from example/pubspec.yaml rename to packages/flutter_background_service/example/pubspec.yaml index 25a49099..8cd58fcc 100644 --- a/example/pubspec.yaml +++ b/packages/flutter_background_service/example/pubspec.yaml @@ -15,10 +15,10 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 +version: 2.0.0 environment: - sdk: ">=2.16.1 <3.0.0" + sdk: ">=2.17.5 <4.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions @@ -38,10 +38,16 @@ dependencies: # the parent directory to use the current plugin's version. path: ../ + flutter_background_service_ios: ^5.0.3 + flutter_background_service_android: ^6.3.1 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.2 - device_info_plus: ^3.2.2 + cupertino_icons: ^1.0.5 + device_info_plus: ^9.0.2 + shared_preferences: ^2.1.2 + + # optional if you wish to use a custom foreground service notification + flutter_local_notifications: ^14.1.1 dev_dependencies: flutter_test: @@ -52,7 +58,7 @@ dev_dependencies: # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. - flutter_lints: ^1.0.0 + flutter_lints: ^2.0.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/example/test/widget_test.dart b/packages/flutter_background_service/example/test/widget_test.dart similarity index 100% rename from example/test/widget_test.dart rename to packages/flutter_background_service/example/test/widget_test.dart diff --git a/example/web/favicon.png b/packages/flutter_background_service/example/web/favicon.png similarity index 100% rename from example/web/favicon.png rename to packages/flutter_background_service/example/web/favicon.png diff --git a/example/web/icons/Icon-192.png b/packages/flutter_background_service/example/web/icons/Icon-192.png similarity index 100% rename from example/web/icons/Icon-192.png rename to packages/flutter_background_service/example/web/icons/Icon-192.png diff --git a/example/web/icons/Icon-512.png b/packages/flutter_background_service/example/web/icons/Icon-512.png similarity index 100% rename from example/web/icons/Icon-512.png rename to packages/flutter_background_service/example/web/icons/Icon-512.png diff --git a/example/web/icons/Icon-maskable-192.png b/packages/flutter_background_service/example/web/icons/Icon-maskable-192.png similarity index 100% rename from example/web/icons/Icon-maskable-192.png rename to packages/flutter_background_service/example/web/icons/Icon-maskable-192.png diff --git a/example/web/icons/Icon-maskable-512.png b/packages/flutter_background_service/example/web/icons/Icon-maskable-512.png similarity index 100% rename from example/web/icons/Icon-maskable-512.png rename to packages/flutter_background_service/example/web/icons/Icon-maskable-512.png diff --git a/example/web/index.html b/packages/flutter_background_service/example/web/index.html similarity index 100% rename from example/web/index.html rename to packages/flutter_background_service/example/web/index.html diff --git a/example/web/manifest.json b/packages/flutter_background_service/example/web/manifest.json similarity index 100% rename from example/web/manifest.json rename to packages/flutter_background_service/example/web/manifest.json diff --git a/example/windows/.gitignore b/packages/flutter_background_service/example/windows/.gitignore similarity index 100% rename from example/windows/.gitignore rename to packages/flutter_background_service/example/windows/.gitignore diff --git a/example/windows/CMakeLists.txt b/packages/flutter_background_service/example/windows/CMakeLists.txt similarity index 100% rename from example/windows/CMakeLists.txt rename to packages/flutter_background_service/example/windows/CMakeLists.txt diff --git a/example/windows/flutter/CMakeLists.txt b/packages/flutter_background_service/example/windows/flutter/CMakeLists.txt similarity index 100% rename from example/windows/flutter/CMakeLists.txt rename to packages/flutter_background_service/example/windows/flutter/CMakeLists.txt diff --git a/example/windows/flutter/generated_plugin_registrant.cc b/packages/flutter_background_service/example/windows/flutter/generated_plugin_registrant.cc similarity index 100% rename from example/windows/flutter/generated_plugin_registrant.cc rename to packages/flutter_background_service/example/windows/flutter/generated_plugin_registrant.cc diff --git a/example/windows/flutter/generated_plugin_registrant.h b/packages/flutter_background_service/example/windows/flutter/generated_plugin_registrant.h similarity index 100% rename from example/windows/flutter/generated_plugin_registrant.h rename to packages/flutter_background_service/example/windows/flutter/generated_plugin_registrant.h diff --git a/example/windows/flutter/generated_plugins.cmake b/packages/flutter_background_service/example/windows/flutter/generated_plugins.cmake similarity index 61% rename from example/windows/flutter/generated_plugins.cmake rename to packages/flutter_background_service/example/windows/flutter/generated_plugins.cmake index 4d10c251..b93c4c30 100644 --- a/example/windows/flutter/generated_plugins.cmake +++ b/packages/flutter_background_service/example/windows/flutter/generated_plugins.cmake @@ -5,6 +5,9 @@ list(APPEND FLUTTER_PLUGIN_LIST ) +list(APPEND FLUTTER_FFI_PLUGIN_LIST +) + set(PLUGIN_BUNDLED_LIBRARIES) foreach(plugin ${FLUTTER_PLUGIN_LIST}) @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST}) list(APPEND PLUGIN_BUNDLED_LIBRARIES $) list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) endforeach(plugin) + +foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) +endforeach(ffi_plugin) diff --git a/example/windows/runner/CMakeLists.txt b/packages/flutter_background_service/example/windows/runner/CMakeLists.txt similarity index 100% rename from example/windows/runner/CMakeLists.txt rename to packages/flutter_background_service/example/windows/runner/CMakeLists.txt diff --git a/example/windows/runner/Runner.rc b/packages/flutter_background_service/example/windows/runner/Runner.rc similarity index 100% rename from example/windows/runner/Runner.rc rename to packages/flutter_background_service/example/windows/runner/Runner.rc diff --git a/example/windows/runner/flutter_window.cpp b/packages/flutter_background_service/example/windows/runner/flutter_window.cpp similarity index 100% rename from example/windows/runner/flutter_window.cpp rename to packages/flutter_background_service/example/windows/runner/flutter_window.cpp diff --git a/example/windows/runner/flutter_window.h b/packages/flutter_background_service/example/windows/runner/flutter_window.h similarity index 100% rename from example/windows/runner/flutter_window.h rename to packages/flutter_background_service/example/windows/runner/flutter_window.h diff --git a/example/windows/runner/main.cpp b/packages/flutter_background_service/example/windows/runner/main.cpp similarity index 100% rename from example/windows/runner/main.cpp rename to packages/flutter_background_service/example/windows/runner/main.cpp diff --git a/example/windows/runner/resource.h b/packages/flutter_background_service/example/windows/runner/resource.h similarity index 100% rename from example/windows/runner/resource.h rename to packages/flutter_background_service/example/windows/runner/resource.h diff --git a/example/windows/runner/resources/app_icon.ico b/packages/flutter_background_service/example/windows/runner/resources/app_icon.ico similarity index 100% rename from example/windows/runner/resources/app_icon.ico rename to packages/flutter_background_service/example/windows/runner/resources/app_icon.ico diff --git a/example/windows/runner/runner.exe.manifest b/packages/flutter_background_service/example/windows/runner/runner.exe.manifest similarity index 100% rename from example/windows/runner/runner.exe.manifest rename to packages/flutter_background_service/example/windows/runner/runner.exe.manifest diff --git a/example/windows/runner/utils.cpp b/packages/flutter_background_service/example/windows/runner/utils.cpp similarity index 100% rename from example/windows/runner/utils.cpp rename to packages/flutter_background_service/example/windows/runner/utils.cpp diff --git a/example/windows/runner/utils.h b/packages/flutter_background_service/example/windows/runner/utils.h similarity index 100% rename from example/windows/runner/utils.h rename to packages/flutter_background_service/example/windows/runner/utils.h diff --git a/example/windows/runner/win32_window.cpp b/packages/flutter_background_service/example/windows/runner/win32_window.cpp similarity index 100% rename from example/windows/runner/win32_window.cpp rename to packages/flutter_background_service/example/windows/runner/win32_window.cpp diff --git a/example/windows/runner/win32_window.h b/packages/flutter_background_service/example/windows/runner/win32_window.h similarity index 100% rename from example/windows/runner/win32_window.h rename to packages/flutter_background_service/example/windows/runner/win32_window.h diff --git a/flutter_background_service.iml b/packages/flutter_background_service/flutter_background_service.iml similarity index 100% rename from flutter_background_service.iml rename to packages/flutter_background_service/flutter_background_service.iml diff --git a/packages/flutter_background_service/lib/flutter_background_service.dart b/packages/flutter_background_service/lib/flutter_background_service.dart new file mode 100644 index 00000000..75a01879 --- /dev/null +++ b/packages/flutter_background_service/lib/flutter_background_service.dart @@ -0,0 +1,47 @@ +library flutter_background_service; + +import 'dart:async'; + +import 'package:flutter_background_service_platform_interface/flutter_background_service_platform_interface.dart'; + +export 'package:flutter_background_service_platform_interface/flutter_background_service_platform_interface.dart' + show IosConfiguration, AndroidConfiguration, ServiceInstance, AndroidForegroundType; + +export 'package:flutter_background_service_android/flutter_background_service_android.dart'; +export 'package:flutter_background_service_ios/flutter_background_service_ios.dart'; + +class FlutterBackgroundService implements Observable { + FlutterBackgroundServicePlatform get _platform => + FlutterBackgroundServicePlatform.instance; + + /// configure the background service handler + /// it's highly recommended to call this method in main() method + Future configure({ + required IosConfiguration iosConfiguration, + required AndroidConfiguration androidConfiguration, + }) => + _platform.configure( + iosConfiguration: iosConfiguration, + androidConfiguration: androidConfiguration, + ); + + static FlutterBackgroundService _instance = + FlutterBackgroundService._internal(); + + FlutterBackgroundService._internal(); + + factory FlutterBackgroundService() => _instance; + + /// Starts the background service. + Future startService() => _platform.start(); + + /// Whether the service is running + Future isRunning() => _platform.isServiceRunning(); + + @override + void invoke(String method, [Map? arg]) => + _platform.invoke(method, arg); + + @override + Stream?> on(String method) => _platform.on(method); +} diff --git a/packages/flutter_background_service/melos_flutter_background_service.iml b/packages/flutter_background_service/melos_flutter_background_service.iml new file mode 100644 index 00000000..87149cbb --- /dev/null +++ b/packages/flutter_background_service/melos_flutter_background_service.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/flutter_background_service/pubspec.yaml b/packages/flutter_background_service/pubspec.yaml new file mode 100644 index 00000000..d0474b03 --- /dev/null +++ b/packages/flutter_background_service/pubspec.yaml @@ -0,0 +1,38 @@ +name: flutter_background_service +description: A flutter plugin for executing dart code continously even application closed. +version: 5.1.1 +repository: https://github.com/ekasetiawans/flutter_background_service + +funding: + - https://www.buymeacoffee.com/ekasetiawans + +environment: + sdk: ">=2.17.5 <4.0.0" + flutter: ">=3.0.0" + +dependencies: + flutter: + sdk: flutter + + flutter_background_service_platform_interface: ^5.1.2 + flutter_background_service_android: ^6.3.1 + flutter_background_service_ios: ^5.0.3 +dev_dependencies: + flutter_test: + sdk: flutter + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: + # This section identifies this Flutter project as a plugin project. + # The 'pluginClass' and Android 'package' identifiers should not ordinarily + # be modified. They are used by the tooling to maintain consistency when + # adding or updating assets for this project. + plugin: + platforms: + android: + default_package: flutter_background_service_android + ios: + default_package: flutter_background_service_ios diff --git a/test/flutter_background_service_test.dart b/packages/flutter_background_service/test/flutter_background_service_test.dart similarity index 100% rename from test/flutter_background_service_test.dart rename to packages/flutter_background_service/test/flutter_background_service_test.dart diff --git a/packages/flutter_background_service_android/.gitignore b/packages/flutter_background_service_android/.gitignore new file mode 100644 index 00000000..899ae641 --- /dev/null +++ b/packages/flutter_background_service_android/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +.dart_tool/ + +.packages +.pub/ + +build/ +pubspec.lock +.idea/ diff --git a/packages/flutter_background_service_android/.metadata b/packages/flutter_background_service_android/.metadata new file mode 100644 index 00000000..669304cf --- /dev/null +++ b/packages/flutter_background_service_android/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 216dee60c0cc9449f0b29bcf922974d612263e24 + channel: stable + +project_type: plugin diff --git a/packages/flutter_background_service_android/.vscode/settings.json b/packages/flutter_background_service_android/.vscode/settings.json new file mode 100644 index 00000000..7f69797d --- /dev/null +++ b/packages/flutter_background_service_android/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dart.runPubGetOnPubspecChanges": false +} \ No newline at end of file diff --git a/packages/flutter_background_service_android/CHANGELOG.md b/packages/flutter_background_service_android/CHANGELOG.md new file mode 100644 index 00000000..d3dc25e9 --- /dev/null +++ b/packages/flutter_background_service_android/CHANGELOG.md @@ -0,0 +1,395 @@ +## 6.3.1 + + - **FIX**(android): add namespace to support AGP 8.0+. ([76b0c396](https://github.com/ekasetiawans/flutter_background_service/commit/76b0c3960e2e65b5be8c60a2de0b7c0565691769)) + - **FIX**: manually disabling Alarms & reminders permission on Android 12 causes an exception when starting service on reboot. ([135fed1f](https://github.com/ekasetiawans/flutter_background_service/commit/135fed1f3a49b5c674718a112beb2ca71a19d1b0)) + +## 6.3.0 + + - **FEAT**: remove unused imports. ([d0bbb433](https://github.com/ekasetiawans/flutter_background_service/commit/d0bbb43312877af51b5403c6fc42dd9ec2a44789)) + +## 6.2.7 + + - **BUG**: service crash due to START_STICKY. ([a000a6ba](https://github.com/ekasetiawans/flutter_background_service/commit/a000a6bae974de543c9f37275e2aab177c197339)) + +## 6.2.6 + + - Update a dependency to the latest release. + +## 6.2.5 + + - **FIX**: lints. ([7b63fca4](https://github.com/ekasetiawans/flutter_background_service/commit/7b63fca4e97941b2891570bd80701c7bb98cda23)) + +## 6.2.4 + + - **FIX**: fix crash on android 14 after starting foreground service. ([4bdc46d9](https://github.com/ekasetiawans/flutter_background_service/commit/4bdc46d951febafbcbb2b118324cddc2b30ad752)) + +## 6.2.3 + + - Update a dependency to the latest release. + +## 6.2.2 + + - **FIX**: android build error. ([8102e015](https://github.com/ekasetiawans/flutter_background_service/commit/8102e01563b967cea588a09b8a9773fc56b0dd2c)) + +## 6.2.1 + + - **FIX**: checks methodChanel's nullabilty inside MainHandler.post. ([cd0d098f](https://github.com/ekasetiawans/flutter_background_service/commit/cd0d098f76fb9e211ab5db1a08f19cfd21827b30)) + - **FIX**: removes listener before turn methodChannel null. ([7909b51c](https://github.com/ekasetiawans/flutter_background_service/commit/7909b51cafbf6e79ad0f875e73889ad1b2b5fc34)) + +## 6.2.0 + + - **FEAT**: throw an error if using FlutterBackgroundService class in worker isolate. ([9a5732ce](https://github.com/ekasetiawans/flutter_background_service/commit/9a5732cef65ce5b33e699569cd88c98521c002ac)) + +## 6.1.0 + + - **FEAT**: throw an error if using FlutterBackgroundService class in worker isolate. ([d09843f8](https://github.com/ekasetiawans/flutter_background_service/commit/d09843f82a6d4a9ef19529ab27701ab68f68ee7c)) + +## 6.0.1 + + - **FIX**: service do not connect to dart side after destroy by xiaomi boost memory. ([a04d3a75](https://github.com/ekasetiawans/flutter_background_service/commit/a04d3a75ca0a8e4683802b0a01e41b0dd50ba37b)) + +## 6.0.0 + +> Note: This release has breaking changes. + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve entrypoint with args. ([5abacbe5](https://github.com/ekasetiawans/flutter_background_service/commit/5abacbe57f239d9ce1667e643d81d6b17f873f5c)) + - **PERF**: using exact alarm for watchdog receiver. ([6dba6670](https://github.com/ekasetiawans/flutter_background_service/commit/6dba6670965a24b9b0657ad0abc793db850a982b)) + - **PERF**: improve android background service. ([e01a3fa2](https://github.com/ekasetiawans/flutter_background_service/commit/e01a3fa2938479f31a525c23ff888c03b496fa70)) + - **FIX**: We still need to check service is running or not. ([280a603e](https://github.com/ekasetiawans/flutter_background_service/commit/280a603ee4fff39e2d0d0cd043dd6ba6f0941ee1)) + - **FIX**: Issue created by [#336](https://github.com/ekasetiawans/flutter_background_service/issues/336). ([6fedeed2](https://github.com/ekasetiawans/flutter_background_service/commit/6fedeed253d2648d876b9a2e3e5a30967934a81a)) + - **FIX**: added proguard for android plugin. ([0d7ac8a6](https://github.com/ekasetiawans/flutter_background_service/commit/0d7ac8a698b339af5931cb3b3e18c4b7f2e2670f)) + - **FIX**: make final variable for backward compatibility of gradle. ([d7087ba0](https://github.com/ekasetiawans/flutter_background_service/commit/d7087ba07a580e7d16d4e416cde43ddfb531e664)) + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + - **FIX**: wakelock not released. ([e427f3b7](https://github.com/ekasetiawans/flutter_background_service/commit/e427f3b70138ec26f9671c2617f9061f25eade6f)) + - **FIX**: autoStartOnBootMode [#160](https://github.com/ekasetiawans/flutter_background_service/issues/160). ([16a785a3](https://github.com/ekasetiawans/flutter_background_service/commit/16a785a3cbcb4226321ddddf681b6554196fa4db)) + - **FIX**: release wakelock. ([c0830250](https://github.com/ekasetiawans/flutter_background_service/commit/c0830250b90a1ba6e2543a1bb25a13fba59a56b7)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FEAT**: added QUICKBOOT_POWERON action to intent-filter. ([46f08173](https://github.com/ekasetiawans/flutter_background_service/commit/46f08173cfb54795fb707bd521d8ed94db75cad5)) + - **FEAT**: revert to single process. ([515dde6a](https://github.com/ekasetiawans/flutter_background_service/commit/515dde6a49e50087c6f613ff0de8e1bd111a315b)) + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + - **FEAT**(android): expose notification id for foreground service. ([47b7089c](https://github.com/ekasetiawans/flutter_background_service/commit/47b7089c5e4ab18f3a35558d6c7ec2d50fc8d3f1)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: autoStartOnBoot now using it's own argument. ([036669dc](https://github.com/ekasetiawans/flutter_background_service/commit/036669dc4383e938f09f88d9d8a248afbf918cf8)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +## 5.0.0 + +> Note: This release has breaking changes. + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve entrypoint with args. ([5abacbe5](https://github.com/ekasetiawans/flutter_background_service/commit/5abacbe57f239d9ce1667e643d81d6b17f873f5c)) + - **PERF**: using exact alarm for watchdog receiver. ([6dba6670](https://github.com/ekasetiawans/flutter_background_service/commit/6dba6670965a24b9b0657ad0abc793db850a982b)) + - **PERF**: improve android background service. ([e01a3fa2](https://github.com/ekasetiawans/flutter_background_service/commit/e01a3fa2938479f31a525c23ff888c03b496fa70)) + - **FIX**: We still need to check service is running or not. ([280a603e](https://github.com/ekasetiawans/flutter_background_service/commit/280a603ee4fff39e2d0d0cd043dd6ba6f0941ee1)) + - **FIX**: Issue created by [#336](https://github.com/ekasetiawans/flutter_background_service/issues/336). ([6fedeed2](https://github.com/ekasetiawans/flutter_background_service/commit/6fedeed253d2648d876b9a2e3e5a30967934a81a)) + - **FIX**: added proguard for android plugin. ([0d7ac8a6](https://github.com/ekasetiawans/flutter_background_service/commit/0d7ac8a698b339af5931cb3b3e18c4b7f2e2670f)) + - **FIX**: make final variable for backward compatibility of gradle. ([d7087ba0](https://github.com/ekasetiawans/flutter_background_service/commit/d7087ba07a580e7d16d4e416cde43ddfb531e664)) + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + - **FIX**: wakelock not released. ([e427f3b7](https://github.com/ekasetiawans/flutter_background_service/commit/e427f3b70138ec26f9671c2617f9061f25eade6f)) + - **FIX**: autoStartOnBootMode [#160](https://github.com/ekasetiawans/flutter_background_service/issues/160). ([16a785a3](https://github.com/ekasetiawans/flutter_background_service/commit/16a785a3cbcb4226321ddddf681b6554196fa4db)) + - **FIX**: release wakelock. ([c0830250](https://github.com/ekasetiawans/flutter_background_service/commit/c0830250b90a1ba6e2543a1bb25a13fba59a56b7)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FEAT**: added QUICKBOOT_POWERON action to intent-filter. ([46f08173](https://github.com/ekasetiawans/flutter_background_service/commit/46f08173cfb54795fb707bd521d8ed94db75cad5)) + - **FEAT**: revert to single process. ([515dde6a](https://github.com/ekasetiawans/flutter_background_service/commit/515dde6a49e50087c6f613ff0de8e1bd111a315b)) + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + - **FEAT**(android): expose notification id for foreground service. ([47b7089c](https://github.com/ekasetiawans/flutter_background_service/commit/47b7089c5e4ab18f3a35558d6c7ec2d50fc8d3f1)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: autoStartOnBoot now using it's own argument. ([036669dc](https://github.com/ekasetiawans/flutter_background_service/commit/036669dc4383e938f09f88d9d8a248afbf918cf8)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +## 4.0.2 + + - **FIX**: We still need to check service is running or not. ([280a603e](https://github.com/ekasetiawans/flutter_background_service/commit/280a603ee4fff39e2d0d0cd043dd6ba6f0941ee1)) + - **FIX**: Issue created by [#336](https://github.com/ekasetiawans/flutter_background_service/issues/336). ([6fedeed2](https://github.com/ekasetiawans/flutter_background_service/commit/6fedeed253d2648d876b9a2e3e5a30967934a81a)) + +## 4.0.1 + + - **REFACTOR**: improve android performances. ([13f73a86](https://github.com/ekasetiawans/flutter_background_service/commit/13f73a86e9c1cc0c5fc46a757992e24219d03715)) + +## 4.0.0 + +> Note: This release has breaking changes. + + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + +## 3.0.3 + +- **FIX**: Android crash when unbinding service + +## 3.0.2 + + - **FIX**: added proguard for android plugin. ([0d7ac8a6](https://github.com/ekasetiawans/flutter_background_service/commit/0d7ac8a698b339af5931cb3b3e18c4b7f2e2670f)) + +## 3.0.1 + +- **FIX**: Android crash when unbinding service + +## 3.0.0 + +> Note: This release has breaking changes. + + - **BREAKING** **FEAT**: autoStartOnBoot now using it's own argument. ([036669dc](https://github.com/ekasetiawans/flutter_background_service/commit/036669dc4383e938f09f88d9d8a248afbf918cf8)) + +## 2.5.4 + + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + +## 2.5.3 + + - **PERF**: improve entrypoint with args. ([5abacbe5](https://github.com/ekasetiawans/flutter_background_service/commit/5abacbe57f239d9ce1667e643d81d6b17f873f5c)) + +## 2.5.2 + + - **PERF**: using exact alarm for watchdog receiver. ([6dba6670](https://github.com/ekasetiawans/flutter_background_service/commit/6dba6670965a24b9b0657ad0abc793db850a982b)) + +## 2.5.1 + +- **FIX**: Android crash when unbinding service + +## 2.5.0 + + - **FEAT**: added QUICKBOOT_POWERON action to intent-filter. ([46f08173](https://github.com/ekasetiawans/flutter_background_service/commit/46f08173cfb54795fb707bd521d8ed94db75cad5)) + +## 2.4.0 + + - **FEAT**: revert to single process. ([515dde6a](https://github.com/ekasetiawans/flutter_background_service/commit/515dde6a49e50087c6f613ff0de8e1bd111a315b)) + +## 2.3.4 + + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + +## 2.3.3 + + - **FIX**: make final variable for backward compatibility of gradle. ([d7087ba0](https://github.com/ekasetiawans/flutter_background_service/commit/d7087ba07a580e7d16d4e416cde43ddfb531e664)) + +## 2.3.2 + + - **FIX**: using Runnable instead of lambda. ([9cda867d](https://github.com/ekasetiawans/flutter_background_service/commit/9cda867d8f2dc84cf1f7f112a3e87b1fa7dc1d3d)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: updated README. ([3885e301](https://github.com/ekasetiawans/flutter_background_service/commit/3885e3017729a557b0b0b7ccdb968692ba7c8a52)) + +## 2.3.1 + + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + +## 2.3.0 + + - **FEAT**: move android service to separated process. ([bd2e6f07](https://github.com/ekasetiawans/flutter_background_service/commit/bd2e6f075ea8a7db231c7586b8f6244bb0399ff4)) + +## 2.2.2 + + - Update a dependency to the latest release. + +## 2.2.1 + + - Update a dependency to the latest release. + +## 2.2.0 + + - **FEAT**: expose notification id for foreground service. ([47b7089c](https://github.com/ekasetiawans/flutter_background_service/commit/47b7089c5e4ab18f3a35558d6c7ec2d50fc8d3f1)) + +## 2.1.1 + + - **PERF**: improve android background service. ([e01a3fa2](https://github.com/ekasetiawans/flutter_background_service/commit/e01a3fa2938479f31a525c23ff888c03b496fa70)) + +## 2.1.0 + + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + +## 2.0.3 + + - **FIX**: wakelock not released. ([e427f3b7](https://github.com/ekasetiawans/flutter_background_service/commit/e427f3b70138ec26f9671c2617f9061f25eade6f)) + +## 2.0.2 + + - **FIX**: autoStartOnBootMode #160. ([16a785a3](https://github.com/ekasetiawans/flutter_background_service/commit/16a785a3cbcb4226321ddddf681b6554196fa4db)) + +## 2.0.1 + + - **FIX**: release wakelock. ([c0830250](https://github.com/ekasetiawans/flutter_background_service/commit/c0830250b90a1ba6e2543a1bb25a13fba59a56b7)) + +## 2.0.0 + + - Graduate package to a stable release. See pre-releases prior to this version for changelog entries. + +## 2.0.0-dev.0 + +> Note: This release has breaking changes. + + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +## 1.0.2 + + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + +## 1.0.1 + + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + +## 0.0.2 + + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + +## 0.0.1+3 + + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + +## 0.0.1+2 + + - Update a dependency to the latest release. + +## 0.0.1+1 + + - **REFACTOR**: initialize melos. + +## 0.2.6 +* FIX: (Android) flutter initialization +## 0.2.5 +* FIX: (iOS) using other plugins +## 0.2.4 +* FIX: (Android) run service background when charger not connected and screen lock (#92) +## 0.2.3 +* ADDED: Using `BGTaskScheduler` on iOS 13. See readme for configuration. +## 0.2.2 +* ADDED: `autoStart` to `IosConfiguration` +## 0.2.1 +* UPDATE README +* UPDATE: Flutter Version Constraint +## 0.2.0+1 +* UPDATE README + +## 0.2.0 +* [BREAKING]: FlutterBackgroundService.initialize renamed to FlutterBackgroundService.configure +* [BREAKING]: use FlutterBackgroundService.start to start or restart after you call stopService. +* [ADDED]: IOS Background fetch is now supported you have to enable background fetch from xcode. +## 0.1.7 + +* Fix : cannot start service on android 12 +* Fix : not started on boot completed +## 0.1.6 + +* Android 12 Compatibility Changes +## 0.1.5 + +* Rollback foreground notification importance +## 0.1.4 + +* fixes UnsatisfiedLinkError when running as foreground service with autostart #32 +## 0.1.3 + +* Fix notification not showing on android 7 and prior (Issue #26) +## 0.1.2 + +* Open app from notification (Issue #30) +## 0.1.1 + +* Fix #29 (DartVM not terminated when service stop) + +## 0.1.0 + +* Bump flutter 2 + +## 0.1.0-nullsafety.2 + +* Fix #23 + +## 0.1.0-nullsafety.1 + +* Added isServiceRunning on iOS (issue #19) + +## 0.1.0-nullsafety.0 + +* Added support to nullsafety + +## 0.0.1+18 + +* Added stopService Method(Currently Works on Android Only). + +## 0.0.1+17 + +* Add preference autoStart on Boot, default is true. + +## 0.0.1+16 + +* Set Foreground Mode to false will remove notification. BugFix #4. + +## 0.0.1+15 + +* Add ability to change Background or Foreground mode (Android Only) + +## 0.0.1+14 + +* Bugfix BootReceiver + +## 0.0.1+13 + +* Update example for iOS support. + +## 0.0.1+12 + +* Start service immediately after initialize + +## 0.0.1+11 + +* iOS + +## 0.0.1+10 + +* bug fix + +## 0.0.1+9 + +* bug fix + +## 0.0.1+8 + +* bug fix + +## 0.0.1+7 + +* Add ability to send data from UI to Service + +## 0.0.1+6 + +* Improve stability + +## 0.0.1+5 + +* Add ability to send data from service to UI + +## 0.0.1+4 + +* Update README + +## 0.0.1+3 + +* Add ability to change notification info (Android foreground service) + +## 0.0.1+2 + +* Fix android missing plugin implementation + +## 0.0.1+1 + +* Fix android build + +## 0.0.1 + +* TODO: Describe initial release. diff --git a/packages/flutter_background_service_android/LICENSE b/packages/flutter_background_service_android/LICENSE new file mode 100644 index 00000000..0b8db9ec --- /dev/null +++ b/packages/flutter_background_service_android/LICENSE @@ -0,0 +1,7 @@ +Copyright 2022 Eka Setiawan Saputra + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/flutter_background_service_android/README.md b/packages/flutter_background_service_android/README.md new file mode 100644 index 00000000..f58a5d39 --- /dev/null +++ b/packages/flutter_background_service_android/README.md @@ -0,0 +1,11 @@ +# flutter\_background\_service\_android + +The Android implementation of [`flutter_background_service`][1]. + +## Usage + +This package is [endorsed][2], which means you can simply use `flutter_background_service` +normally. This package will be automatically included in your app when you do. + +[1]: https://pub.dev/packages/flutter_background_service +[2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin \ No newline at end of file diff --git a/android/.gitignore b/packages/flutter_background_service_android/android/.gitignore similarity index 100% rename from android/.gitignore rename to packages/flutter_background_service_android/android/.gitignore diff --git a/android/build.gradle b/packages/flutter_background_service_android/android/build.gradle similarity index 57% rename from android/build.gradle rename to packages/flutter_background_service_android/android/build.gradle index 3459b085..37e74089 100644 --- a/android/build.gradle +++ b/packages/flutter_background_service_android/android/build.gradle @@ -4,34 +4,38 @@ version '1.0' buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:7.4.2' } } rootProject.allprojects { repositories { google() - jcenter() + mavenCentral() } } apply plugin: 'com.android.library' android { - compileSdkVersion 31 + compileSdkVersion 34 + namespace = "id.flutter.flutter_background_service" + defaultConfig { minSdkVersion 16 + consumerProguardFiles 'proguard-rules.pro' } + lintOptions { disable 'InvalidPackage' } } dependencies { - implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' -} \ No newline at end of file + implementation "androidx.core:core:1.12.0" +} diff --git a/android/gradle.properties b/packages/flutter_background_service_android/android/gradle.properties similarity index 100% rename from android/gradle.properties rename to packages/flutter_background_service_android/android/gradle.properties diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/packages/flutter_background_service_android/android/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from android/gradle/wrapper/gradle-wrapper.properties rename to packages/flutter_background_service_android/android/gradle/wrapper/gradle-wrapper.properties diff --git a/packages/flutter_background_service_android/android/proguard-rules.pro b/packages/flutter_background_service_android/android/proguard-rules.pro new file mode 100644 index 00000000..50123c59 --- /dev/null +++ b/packages/flutter_background_service_android/android/proguard-rules.pro @@ -0,0 +1,2 @@ +-keep class id.flutter.flutter_background_service.** { *; } +-keepclassmembers class id.flutter.flutter_background_service.** {*;} \ No newline at end of file diff --git a/android/settings.gradle b/packages/flutter_background_service_android/android/settings.gradle similarity index 100% rename from android/settings.gradle rename to packages/flutter_background_service_android/android/settings.gradle diff --git a/android/src/main/AndroidManifest.xml b/packages/flutter_background_service_android/android/src/main/AndroidManifest.xml similarity index 74% rename from android/src/main/AndroidManifest.xml rename to packages/flutter_background_service_android/android/src/main/AndroidManifest.xml index e0d0392f..a3db7697 100644 --- a/android/src/main/AndroidManifest.xml +++ b/packages/flutter_background_service_android/android/src/main/AndroidManifest.xml @@ -7,24 +7,28 @@ - - - + + diff --git a/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/BackgroundService.java b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/BackgroundService.java new file mode 100644 index 00000000..a8604483 --- /dev/null +++ b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/BackgroundService.java @@ -0,0 +1,351 @@ +package id.flutter.flutter_background_service; + +import static android.os.Build.VERSION.SDK_INT; + +import android.annotation.SuppressLint; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.os.Handler; +import android.os.IBinder; +import android.os.Looper; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.core.app.NotificationCompat; +import androidx.core.app.ServiceCompat; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import io.flutter.FlutterInjector; +import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.embedding.engine.dart.DartExecutor; +import io.flutter.embedding.engine.loader.FlutterLoader; +import io.flutter.plugin.common.JSONMethodCodec; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; + +public class BackgroundService extends Service implements MethodChannel.MethodCallHandler { + private static final String TAG = "BackgroundService"; + private static final String LOCK_NAME = BackgroundService.class.getName() + + ".Lock"; + public static volatile WakeLock lockStatic = null; // notice static + AtomicBoolean isRunning = new AtomicBoolean(false); + private FlutterEngine backgroundEngine; + private MethodChannel methodChannel; + private Config config; + private DartExecutor.DartEntrypoint dartEntrypoint; + private boolean isManuallyStopped = false; + private String notificationTitle; + private String notificationContent; + private String notificationChannelId; + private int notificationId; + private String configForegroundTypes; + private String[] foregroundTypes; + private Handler mainHandler; + + synchronized public static PowerManager.WakeLock getLock(Context context) { + if (lockStatic == null) { + PowerManager mgr = (PowerManager) context + .getSystemService(Context.POWER_SERVICE); + lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, + LOCK_NAME); + lockStatic.setReferenceCounted(true); + } + + return lockStatic; + } + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public boolean onUnbind(Intent intent) { + return super.onUnbind(intent); + } + + @Override + public void onCreate() { + super.onCreate(); + + FlutterBackgroundServicePlugin.servicePipe.addListener(listener); + + config = new Config(this); + mainHandler = new Handler(Looper.getMainLooper()); + + String notificationChannelId = config.getNotificationChannelId(); + if (notificationChannelId == null) { + this.notificationChannelId = "FOREGROUND_DEFAULT"; + createNotificationChannel(); + } else { + this.notificationChannelId = notificationChannelId; + } + + notificationTitle = config.getInitialNotificationTitle(); + notificationContent = config.getInitialNotificationContent(); + notificationId = config.getForegroundNotificationId(); + configForegroundTypes = config.getForegroundServiceTypes(); + updateNotificationInfo(); + onStartCommand(null, -1, -1); + } + + @Override + public void onDestroy() { + if (!isManuallyStopped) { + WatchdogReceiver.enqueue(this); + } else { + config.setManuallyStopped(true); + } + stopForeground(true); + isRunning.set(false); + + if (backgroundEngine != null) { + backgroundEngine.getServiceControlSurface().detachFromService(); + backgroundEngine.destroy(); + backgroundEngine = null; + } + + FlutterBackgroundServicePlugin.servicePipe.removeListener(listener); + methodChannel = null; + dartEntrypoint = null; + super.onDestroy(); + } + + private final Pipe.PipeListener listener = new Pipe.PipeListener() { + @Override + public void onReceived(JSONObject object) { + receiveData(object); + } + }; + + private void createNotificationChannel() { + if (SDK_INT >= Build.VERSION_CODES.O) { + CharSequence name = "Background Service"; + String description = "Executing process in background"; + + int importance = NotificationManager.IMPORTANCE_LOW; + NotificationChannel channel = new NotificationChannel(notificationChannelId, name, importance); + channel.setDescription(description); + + NotificationManager notificationManager = getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel(channel); + } + } + + protected void updateNotificationInfo() { + if (config.isForeground()) { + String packageName = getApplicationContext().getPackageName(); + Intent i = getPackageManager().getLaunchIntentForPackage(packageName); + + int flags = PendingIntent.FLAG_CANCEL_CURRENT; + if (SDK_INT >= Build.VERSION_CODES.S) { + flags |= PendingIntent.FLAG_MUTABLE; + } + + PendingIntent pi = PendingIntent.getActivity(BackgroundService.this, 11, i, flags); + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, notificationChannelId) + .setSmallIcon(R.drawable.ic_bg_service_small) + .setAutoCancel(true) + .setOngoing(true) + .setContentTitle(notificationTitle) + .setContentText(notificationContent) + .setContentIntent(pi); + + try { + foregroundTypes = null; + if (configForegroundTypes != null && !configForegroundTypes.isEmpty()) { + foregroundTypes = configForegroundTypes.split(","); + } + Integer serviceType = ForegroundTypeMapper.getForegroundServiceType(foregroundTypes); + ServiceCompat.startForeground(this, notificationId, mBuilder.build(), serviceType); + } catch (SecurityException e) { + Log.w(TAG, "Failed to start foreground service due to SecurityException - have you forgotten to request a permission? - " + e.getMessage()); + } + } + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + config.setManuallyStopped(false); + WatchdogReceiver.enqueue(this); + runService(); + + return START_NOT_STICKY; + } + + @SuppressLint("WakelockTimeout") + private void runService() { + try { + if (isRunning.get() || (backgroundEngine != null && !backgroundEngine.getDartExecutor().isExecutingDart())) { + Log.v(TAG, "Service already running, using existing service"); + return; + } + + Log.v(TAG, "Starting flutter engine for background service"); + getLock(getApplicationContext()).acquire(); + + updateNotificationInfo(); + + FlutterLoader flutterLoader = FlutterInjector.instance().flutterLoader(); + // initialize flutter if it's not initialized yet + if (!flutterLoader.initialized()) { + flutterLoader.startInitialization(getApplicationContext()); + } + + flutterLoader.ensureInitializationComplete(getApplicationContext(), null); + + isRunning.set(true); + backgroundEngine = new FlutterEngine(this); + + // remove FlutterBackgroundServicePlugin (because its only for UI) + backgroundEngine.getPlugins().remove(FlutterBackgroundServicePlugin.class); + + backgroundEngine.getServiceControlSurface().attachToService(BackgroundService.this, null, config.isForeground()); + + methodChannel = new MethodChannel(backgroundEngine.getDartExecutor().getBinaryMessenger(), "id.flutter/background_service_android_bg", JSONMethodCodec.INSTANCE); + methodChannel.setMethodCallHandler(this); + + dartEntrypoint = new DartExecutor.DartEntrypoint(flutterLoader.findAppBundlePath(), "package:flutter_background_service_android/flutter_background_service_android.dart", "entrypoint"); + + final List args = new ArrayList<>(); + long backgroundHandle = config.getBackgroundHandle(); + args.add(String.valueOf(backgroundHandle)); + + + backgroundEngine.getDartExecutor().executeDartEntrypoint(dartEntrypoint, args); + + } catch (UnsatisfiedLinkError e) { + notificationContent = "Error " + e.getMessage(); + updateNotificationInfo(); + + Log.w(TAG, "UnsatisfiedLinkError: After a reboot this may happen for a short period and it is ok to ignore then!" + e.getMessage()); + } + } + + public void receiveData(JSONObject data) { + if (methodChannel == null) return; + try { + final JSONObject arg = data; + mainHandler.post(() -> { + if (methodChannel == null) return; + methodChannel.invokeMethod("onReceiveData", arg); + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void onTaskRemoved(Intent rootIntent) { + if (isRunning.get()) { + WatchdogReceiver.enqueue(getApplicationContext(), 1000); + } + } + + @Override + public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { + String method = call.method; + + try { + if (method.equalsIgnoreCase("setNotificationInfo")) { + JSONObject arg = (JSONObject) call.arguments; + if (arg.has("title")) { + notificationTitle = arg.getString("title"); + notificationContent = arg.getString("content"); + updateNotificationInfo(); + result.success(true); + } + return; + } + + if (method.equalsIgnoreCase("setAutoStartOnBootMode")) { + JSONObject arg = (JSONObject) call.arguments; + boolean value = arg.getBoolean("value"); + config.setAutoStartOnBoot(value); + result.success(true); + return; + } + + if (method.equalsIgnoreCase("setForegroundMode")) { + JSONObject arg = (JSONObject) call.arguments; + boolean value = arg.getBoolean("value"); + config.setIsForeground(value); + if (value) { + updateNotificationInfo(); + backgroundEngine.getServiceControlSurface().onMoveToForeground(); + } else { + stopForeground(true); + backgroundEngine.getServiceControlSurface().onMoveToBackground(); + } + + result.success(true); + return; + } + + if (method.equalsIgnoreCase("isForegroundMode")) { + boolean value = config.isForeground(); + result.success(value); + return; + } + + if (method.equalsIgnoreCase("stopService")) { + isManuallyStopped = true; + WatchdogReceiver.remove(this); + stopSelf(); + result.success(true); + return; + } + + if (method.equalsIgnoreCase("sendData")) { + try { + if (FlutterBackgroundServicePlugin.mainPipe.hasListener()){ + FlutterBackgroundServicePlugin.mainPipe.invoke((JSONObject) call.arguments); + } + + result.success(true); + } catch (Exception e) { + result.error("send-data-failure", e.getMessage(), e); + } + return; + } + + if(method.equalsIgnoreCase("openApp")){ + try{ + String packageName= getPackageName(); + Intent launchIntent= getPackageManager().getLaunchIntentForPackage(packageName); + if (launchIntent != null) { + launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + + startActivity(launchIntent); + result.success(true); + + } + }catch (Exception e){ + result.error("open app failure", e.getMessage(),e); + + } + return; + + } + } catch (JSONException e) { + Log.e(TAG, e.getMessage()); + e.printStackTrace(); + } + + result.notImplemented(); + } +} diff --git a/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/BootReceiver.java b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/BootReceiver.java new file mode 100644 index 00000000..36a7fd1d --- /dev/null +++ b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/BootReceiver.java @@ -0,0 +1,31 @@ +package id.flutter.flutter_background_service; + +import android.annotation.SuppressLint; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import androidx.core.content.ContextCompat; + + +public class BootReceiver extends BroadcastReceiver { + @SuppressLint("WakelockTimeout") + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(Intent.ACTION_MY_PACKAGE_REPLACED) || intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) || intent.getAction().equals("android.intent.action.QUICKBOOT_POWERON")) { + final Config config = new Config(context); + boolean autoStart = config.isAutoStartOnBoot(); + if (autoStart) { + if (BackgroundService.lockStatic == null) { + BackgroundService.getLock(context).acquire(); + } + + if (config.isForeground()) { + ContextCompat.startForegroundService(context, new Intent(context, BackgroundService.class)); + } else { + context.startService(new Intent(context, BackgroundService.class)); + } + } + } + } +} diff --git a/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/Config.java b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/Config.java new file mode 100644 index 00000000..efc54935 --- /dev/null +++ b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/Config.java @@ -0,0 +1,89 @@ +package id.flutter.flutter_background_service; + +import android.content.Context; +import android.content.SharedPreferences; + +public class Config { + final SharedPreferences pref; + + public Config(Context context) { + this.pref = context.getSharedPreferences("id.flutter.background_service", Context.MODE_PRIVATE); + } + + public boolean isAutoStartOnBoot() { + return pref.getBoolean("auto_start_on_boot", false); + } + + public void setAutoStartOnBoot(boolean value) { + pref.edit() + .putBoolean("auto_start_on_boot", value) + .apply(); + } + + public boolean isForeground() { + return pref.getBoolean("is_foreground", false); + } + + public void setIsForeground(boolean value) { + pref.edit() + .putBoolean("is_foreground", value) + .apply(); + } + + public boolean isManuallyStopped() { + return pref.getBoolean("is_manually_stopped", false); + } + + public void setManuallyStopped(boolean value) { + pref.edit().putBoolean("is_manually_stopped", value).apply(); + } + + public long getBackgroundHandle() { + return pref.getLong("background_handle", 0); + } + + public void setBackgroundHandle(long value) { + pref.edit().putLong("background_handle", value).apply(); + } + + public String getInitialNotificationTitle() { + return pref.getString("initial_notification_title", "Background Service"); + } + + public void setInitialNotificationTitle(String value) { + pref.edit().putString("initial_notification_title", value).apply(); + } + + public String getInitialNotificationContent() { + return pref.getString("initial_notification_content", "Preparing"); + } + + public void setInitialNotificationContent(String value) { + pref.edit().putString("initial_notification_content", value).apply(); + } + + public String getNotificationChannelId() { + return pref.getString("notification_channel_id", null); + } + + public void setNotificationChannelId(String value) { + pref.edit().putString("notification_channel_id", value).apply(); + } + + public int getForegroundNotificationId() { + return pref.getInt("foreground_notification_id", 112233); + } + + public void setForegroundNotificationId(int value) { + pref.edit().putInt("foreground_notification_id", value).apply(); + } + + public String getForegroundServiceTypes() { + return pref.getString("foreground_service_types", null); + } + + public void setForegroundServiceTypes(String value) { + pref.edit().putString("foreground_service_types", value).apply(); + } + +} diff --git a/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/FlutterBackgroundServicePlugin.java b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/FlutterBackgroundServicePlugin.java new file mode 100644 index 00000000..97597922 --- /dev/null +++ b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/FlutterBackgroundServicePlugin.java @@ -0,0 +1,210 @@ +package id.flutter.flutter_background_service; + +import android.app.ActivityManager; +import android.content.Context; +import android.content.Intent; +import android.os.Handler; +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.HashMap; +import java.util.Map; + +import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.embedding.engine.plugins.FlutterPlugin; +import io.flutter.plugin.common.EventChannel; +import io.flutter.plugin.common.JSONMethodCodec; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; +import io.flutter.plugin.common.MethodChannel.Result; + +/** + * FlutterBackgroundServicePlugin + */ +public class FlutterBackgroundServicePlugin implements FlutterPlugin, MethodCallHandler, EventChannel.StreamHandler { + private static final String TAG = "BackgroundServicePlugin"; + private Handler mainHandler; + private Config config; + private MethodChannel channel; + private EventChannel eventChannel; + private final Map eventSinks = new HashMap<>(); + + private Context context; + + public static final Pipe servicePipe = new Pipe(); + public static final Pipe mainPipe = new Pipe(); + + public static void registerWith(FlutterEngine engine){ + Log.d(TAG, "registering with FlutterEngine"); + } + + private final Pipe.PipeListener listener = new Pipe.PipeListener() { + @Override + public void onReceived(JSONObject object) { + receiveData(object); + } + }; + + + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { + this.context = flutterPluginBinding.getApplicationContext(); + this.config = new Config(this.context); + + mainHandler = new Handler(context.getMainLooper()); + + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "id.flutter/background_service/android/method", JSONMethodCodec.INSTANCE); + channel.setMethodCallHandler(this); + + eventChannel = new EventChannel(flutterPluginBinding.getBinaryMessenger(), "id.flutter/background_service/android/event", JSONMethodCodec.INSTANCE); + eventChannel.setStreamHandler(this); + + mainPipe.addListener(listener); + } + + private void start() { + WatchdogReceiver.enqueue(context); + boolean isForeground = config.isForeground(); + Intent intent = new Intent(context, BackgroundService.class); + + if (isForeground) { + ContextCompat.startForegroundService(context, intent); + } else { + context.startService(intent); + } + } + + @Override + public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { + String method = call.method; + JSONObject arg = (JSONObject) call.arguments; + + try { + if ("configure".equals(method)) { + long backgroundHandle = arg.getLong("background_handle"); + boolean isForeground = arg.getBoolean("is_foreground_mode"); + boolean autoStartOnBoot = arg.getBoolean("auto_start_on_boot"); + boolean autoStart = arg.getBoolean("auto_start"); + String initialNotificationTitle = arg.isNull("initial_notification_title") ? null : arg.getString("initial_notification_title"); + String initialNotificationContent = arg.isNull("initial_notification_content") ? null : arg.getString("initial_notification_content"); + String notificationChannelId = arg.isNull("notification_channel_id") ? null : arg.getString("notification_channel_id"); + int foregroundNotificationId = arg.isNull("foreground_notification_id") ? null : arg.getInt("foreground_notification_id"); + JSONArray foregroundServiceTypes = arg.isNull("foreground_service_types") ? null : arg.getJSONArray("foreground_service_types"); + String foregroundServiceTypesStr = null; + if (foregroundServiceTypes != null) { + StringBuilder resultForegroundServiceType = new StringBuilder(); + for (int i = 0; i < foregroundServiceTypes.length(); i++) { + resultForegroundServiceType.append(foregroundServiceTypes.getString(i)); + if (i < foregroundServiceTypes.length() - 1) { + resultForegroundServiceType.append(","); + } + } + foregroundServiceTypesStr = resultForegroundServiceType.toString(); + } + + config.setBackgroundHandle(backgroundHandle); + config.setIsForeground(isForeground); + config.setAutoStartOnBoot(autoStartOnBoot); + config.setInitialNotificationTitle(initialNotificationTitle); + config.setInitialNotificationContent(initialNotificationContent); + config.setNotificationChannelId(notificationChannelId); + config.setForegroundNotificationId(foregroundNotificationId); + config.setForegroundServiceTypes(foregroundServiceTypesStr); + + if (autoStart) { + start(); + } + + result.success(true); + return; + } + + if ("start".equals(method)) { + start(); + result.success(true); + return; + } + + if (method.equalsIgnoreCase("sendData")) { + synchronized (servicePipe){ + if (servicePipe.hasListener()){ + servicePipe.invoke((JSONObject) call.arguments); + result.success(true); + return; + } + + result.success(false); + } + return; + } + + if (method.equalsIgnoreCase("isServiceRunning")) { + result.success(isServiceRunning()); + return; + } + + result.notImplemented(); + } catch (Exception e) { + result.error("100", "Failed while read arguments", e.getMessage()); + } + } + + private boolean isServiceRunning() { + ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if (BackgroundService.class.getName().equals(service.service.getClassName())) { + return true; + } + } + return false; + } + + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + mainPipe.removeListener(listener); + + channel.setMethodCallHandler(null); + channel = null; + + synchronized (eventSinks){ + eventSinks.clear(); + } + eventChannel.setStreamHandler(null); + eventChannel = null; + } + + private void receiveData(JSONObject data) { + final JSONObject arg = data; + synchronized (this){ + for (EventChannel.EventSink sink : + eventSinks.values()) { + mainHandler.post(new Runnable() { + @Override + public void run() { + sink.success(arg); + } + }); + } + } + } + + @Override + public void onListen(Object arguments, EventChannel.EventSink events) { + synchronized (this){ + eventSinks.put(arguments, events); + } + } + + @Override + public void onCancel(Object arguments) { + synchronized (this){ + eventSinks.remove(arguments); + } + } +} diff --git a/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/ForegroundTypeMapper.java b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/ForegroundTypeMapper.java new file mode 100644 index 00000000..4865defd --- /dev/null +++ b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/ForegroundTypeMapper.java @@ -0,0 +1,38 @@ +package id.flutter.flutter_background_service; + +import android.content.pm.ServiceInfo; + +import java.util.HashMap; +import java.util.Map; + +public class ForegroundTypeMapper { + + private static final Map foregroundTypeMap = new HashMap<>(); + + static { + foregroundTypeMap.put("camera", ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA); + foregroundTypeMap.put("connectedDevice", ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE); + foregroundTypeMap.put("dataSync", ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC); + foregroundTypeMap.put("health", ServiceInfo.FOREGROUND_SERVICE_TYPE_HEALTH); + foregroundTypeMap.put("location", ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION); + foregroundTypeMap.put("mediaPlayback", ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); + foregroundTypeMap.put("mediaProjection", ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION); + foregroundTypeMap.put("microphone", ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE); + foregroundTypeMap.put("phoneCall", ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL); + foregroundTypeMap.put("remoteMessaging", ServiceInfo.FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING); + foregroundTypeMap.put("shortService", ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE); + foregroundTypeMap.put("specialUse", ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE); + foregroundTypeMap.put("systemExempted", ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED); + } + + public static Integer getForegroundServiceType(String[] foregroundTypes) { + Integer foregroundServiceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST; + if (foregroundTypes != null && foregroundTypes.length > 0) { + foregroundServiceType = 0; + for (String foregroundType : foregroundTypes) { + foregroundServiceType |= foregroundTypeMap.get(foregroundType); + } + } + return foregroundServiceType; + } +} \ No newline at end of file diff --git a/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/Pipe.java b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/Pipe.java new file mode 100644 index 00000000..551526e3 --- /dev/null +++ b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/Pipe.java @@ -0,0 +1,40 @@ +package id.flutter.flutter_background_service; + +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class Pipe { + public interface PipeListener { + public void onReceived(JSONObject object); + } + + private final List listeners = new ArrayList<>(); + public boolean hasListener() { + return !listeners.isEmpty(); + } + + public void addListener(PipeListener listener){ + synchronized (this){ + this.listeners.add(listener); + } + } + + public void removeListener(PipeListener listener){ + synchronized (this){ + this.listeners.remove(listener); + } + } + + public void invoke(JSONObject object){ + synchronized (this) { + if (!listeners.isEmpty()) { + for (PipeListener listener : + this.listeners) { + listener.onReceived(object); + } + } + } + } +} diff --git a/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/WatchdogReceiver.java b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/WatchdogReceiver.java new file mode 100644 index 00000000..9bfdec3c --- /dev/null +++ b/packages/flutter_background_service_android/android/src/main/java/id/flutter/flutter_background_service/WatchdogReceiver.java @@ -0,0 +1,99 @@ +package id.flutter.flutter_background_service; + +import static android.content.Context.ALARM_SERVICE; +import static android.os.Build.VERSION.SDK_INT; + +import android.Manifest; +import android.app.ActivityManager; +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Build; + +import androidx.core.app.AlarmManagerCompat; +import androidx.core.content.ContextCompat; + +public class WatchdogReceiver extends BroadcastReceiver { + private static final int QUEUE_REQUEST_ID = 111; + private static final String ACTION_RESPAWN = "id.flutter.background_service.RESPAWN"; + + public static void enqueue(Context context) { + enqueue(context, 5000); + } + + public static void enqueue(Context context, int millis) { + Intent intent = new Intent(context, WatchdogReceiver.class); + intent.setAction(ACTION_RESPAWN); + AlarmManager manager = (AlarmManager) context.getSystemService(ALARM_SERVICE); + + int flags = PendingIntent.FLAG_UPDATE_CURRENT; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + flags |= PendingIntent.FLAG_MUTABLE; + } + + PendingIntent pIntent = PendingIntent.getBroadcast(context, QUEUE_REQUEST_ID, intent, flags); + + // On some vendored Android 12 (SDK 32) SCHEDULE_EXACT_ALARM permission might not be granted + // by default. + boolean isScheduleExactAlarmsGranted = true; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + isScheduleExactAlarmsGranted = manager.canScheduleExactAlarms(); + } + + // Check is background service every 5 seconds + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU || !isScheduleExactAlarmsGranted) { + // Android 13 (SDK 33) requires apps to declare android.permission.SCHEDULE_EXACT_ALARM to use setExact + // Android 14 (SDK 34) takes this further and requires that apps explicitly ask for user permission before + // using setExact. + // On these versions, use setAndAllowWhileIdle instead - it is _almost_ the same, but allows the OS to delay + // the alarm a bit to minimize device wake-ups + AlarmManagerCompat.setAndAllowWhileIdle(manager, AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millis, pIntent); + } else { + AlarmManagerCompat.setExact(manager, AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millis, pIntent); + } + } + + public static void remove(Context context) { + Intent intent = new Intent(context, WatchdogReceiver.class); + intent.setAction(ACTION_RESPAWN); + + int flags = PendingIntent.FLAG_CANCEL_CURRENT; + if (SDK_INT >= Build.VERSION_CODES.S) { + flags |= PendingIntent.FLAG_MUTABLE; + } + + PendingIntent pi = PendingIntent.getBroadcast(context, WatchdogReceiver.QUEUE_REQUEST_ID, intent, flags); + AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); + alarmManager.cancel(pi); + } + + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(ACTION_RESPAWN)) { + final Config config = new Config(context); + boolean isRunning = false; + + ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if (BackgroundService.class.getName().equals(service.service.getClassName())) { + isRunning = true; + } + } + + if (!config.isManuallyStopped() && !isRunning) { + try { + if (config.isForeground()) { + ContextCompat.startForegroundService(context, new Intent(context, id.flutter.flutter_background_service.BackgroundService.class)); + } else { + context.getApplicationContext().startService(new Intent(context, id.flutter.flutter_background_service.BackgroundService.class)); + }} + catch (Exception e){ + e.printStackTrace(); + } + } + } + } +} diff --git a/android/src/main/res/drawable-hdpi/ic_bg_service_small.png b/packages/flutter_background_service_android/android/src/main/res/drawable-hdpi/ic_bg_service_small.png similarity index 100% rename from android/src/main/res/drawable-hdpi/ic_bg_service_small.png rename to packages/flutter_background_service_android/android/src/main/res/drawable-hdpi/ic_bg_service_small.png diff --git a/android/src/main/res/drawable-mdpi/ic_bg_service_small.png b/packages/flutter_background_service_android/android/src/main/res/drawable-mdpi/ic_bg_service_small.png similarity index 100% rename from android/src/main/res/drawable-mdpi/ic_bg_service_small.png rename to packages/flutter_background_service_android/android/src/main/res/drawable-mdpi/ic_bg_service_small.png diff --git a/android/src/main/res/drawable-xhdpi/ic_bg_service_small.png b/packages/flutter_background_service_android/android/src/main/res/drawable-xhdpi/ic_bg_service_small.png similarity index 100% rename from android/src/main/res/drawable-xhdpi/ic_bg_service_small.png rename to packages/flutter_background_service_android/android/src/main/res/drawable-xhdpi/ic_bg_service_small.png diff --git a/android/src/main/res/drawable-xxhdpi/ic_bg_service_small.png b/packages/flutter_background_service_android/android/src/main/res/drawable-xxhdpi/ic_bg_service_small.png similarity index 100% rename from android/src/main/res/drawable-xxhdpi/ic_bg_service_small.png rename to packages/flutter_background_service_android/android/src/main/res/drawable-xxhdpi/ic_bg_service_small.png diff --git a/packages/flutter_background_service_android/flutter_background_service.iml b/packages/flutter_background_service_android/flutter_background_service.iml new file mode 100644 index 00000000..429df7da --- /dev/null +++ b/packages/flutter_background_service_android/flutter_background_service.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/flutter_background_service_android/lib/flutter_background_service_android.dart b/packages/flutter_background_service_android/lib/flutter_background_service_android.dart new file mode 100644 index 00000000..509f71c3 --- /dev/null +++ b/packages/flutter_background_service_android/lib/flutter_background_service_android.dart @@ -0,0 +1,243 @@ +library flutter_background_service_android; + +import 'dart:async'; +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_background_service_platform_interface/flutter_background_service_platform_interface.dart'; + +bool _isMainIsolate = true; + +@pragma('vm:entry-point') +Future entrypoint(List args) async { + WidgetsFlutterBinding.ensureInitialized(); + _isMainIsolate = false; + + final service = AndroidServiceInstance._(); + final int handle = int.parse(args.first); + final callbackHandle = CallbackHandle.fromRawHandle(handle); + final onStart = PluginUtilities.getCallbackFromHandle(callbackHandle); + if (onStart != null) { + onStart(service); + } +} + +class FlutterBackgroundServiceAndroid extends FlutterBackgroundServicePlatform { + /// Registers this class as the default instance of [FlutterBackgroundServicePlatform]. + static void registerWith() { + FlutterBackgroundServicePlatform.instance = + FlutterBackgroundServiceAndroid(); + } + + FlutterBackgroundServiceAndroid._(); + static final FlutterBackgroundServiceAndroid _instance = + FlutterBackgroundServiceAndroid._(); + + factory FlutterBackgroundServiceAndroid() { + if (!_isMainIsolate) { + throw Exception( + "This class should only be used in the main isolate (UI App)", + ); + } + + return _instance; + } + + Future _handleMethodCall(MethodCall call) async { + debugPrint(call.method); + + switch (call.method) { + case "onReceiveData": + _controller.sink.add(call.arguments); + break; + default: + } + } + + Future start() async { + final result = await _channel.invokeMethod('start'); + return result ?? false; + } + + final MethodChannel _channel = MethodChannel( + 'id.flutter/background_service/android/method', + JSONMethodCodec(), + ); + + final EventChannel _eventChannel = EventChannel( + 'id.flutter/background_service/android/event', + JSONMethodCodec(), + ); + + StreamSubscription? _eventChannelListener; + Future configure({ + required IosConfiguration iosConfiguration, + required AndroidConfiguration androidConfiguration, + }) async { + _channel.setMethodCallHandler(_handleMethodCall); + + _eventChannelListener?.cancel(); + _eventChannelListener = + _eventChannel.receiveBroadcastStream().listen((event) { + _controller.sink.add(event); + }); + + final CallbackHandle? handle = + PluginUtilities.getCallbackHandle(androidConfiguration.onStart); + + if (handle == null) { + throw 'onStart method must be a top-level or static function'; + } + + List? configForegroundServiceTypes = + androidConfiguration.foregroundServiceTypes; + List? foregroundServiceTypes; + if (configForegroundServiceTypes != null && + configForegroundServiceTypes.length > 0) { + foregroundServiceTypes = []; + androidConfiguration.foregroundServiceTypes! + .forEach((foregroundServiceType) { + foregroundServiceTypes!.add(foregroundServiceType.name); + }); + } + + final result = await _channel.invokeMethod( + "configure", + { + "background_handle": handle.toRawHandle(), + "is_foreground_mode": androidConfiguration.isForegroundMode, + "auto_start": androidConfiguration.autoStart, + "auto_start_on_boot": androidConfiguration.autoStartOnBoot, + "initial_notification_content": + androidConfiguration.initialNotificationContent, + "initial_notification_title": + androidConfiguration.initialNotificationTitle, + "notification_channel_id": androidConfiguration.notificationChannelId, + "foreground_notification_id": + androidConfiguration.foregroundServiceNotificationId, + "foreground_service_types": foregroundServiceTypes, + }, + ); + + return result ?? false; + } + + Future isServiceRunning() async { + var result = await _channel.invokeMethod("isServiceRunning"); + return result ?? false; + } + + final _controller = StreamController.broadcast(sync: true); + + void dispose() { + _controller.close(); + } + + @override + void invoke(String method, [Map? args]) { + _channel.invokeMethod("sendData", { + 'method': method, + 'args': args, + }); + } + + @override + Stream?> on(String method) { + return _controller.stream.transform( + StreamTransformer.fromHandlers( + handleData: (data, sink) { + if (data['method'] == method) { + sink.add(data['args']); + } + }, + ), + ); + } +} + +class AndroidServiceInstance extends ServiceInstance { + static const MethodChannel _channel = const MethodChannel( + 'id.flutter/background_service_android_bg', + JSONMethodCodec(), + ); + + AndroidServiceInstance._() { + _channel.setMethodCallHandler(_handleMethodCall); + } + + final _controller = StreamController.broadcast(sync: true); + Future _handleMethodCall(MethodCall call) async { + switch (call.method) { + case "onReceiveData": + _controller.sink.add(call.arguments); + break; + default: + } + } + + @override + void invoke(String method, [Map? args]) { + _channel.invokeMethod('sendData', { + 'method': method, + 'args': args, + }); + } + + @override + Future stopSelf() async { + await _channel.invokeMethod("stopService"); + } + + @override + Stream?> on(String method) { + return _controller.stream.transform( + StreamTransformer.fromHandlers( + handleData: (data, sink) { + if (data['method'] == method) { + sink.add(data['args']); + } + }, + ), + ); + } + + Future setForegroundNotificationInfo({ + required String title, + required String content, + }) async { + await _channel.invokeMethod("setNotificationInfo", { + "title": title, + "content": content, + }); + } + + Future setAsForegroundService() async { + await _channel.invokeMethod("setForegroundMode", { + 'value': true, + }); + } + + Future setAsBackgroundService() async { + await _channel.invokeMethod("setForegroundMode", { + 'value': false, + }); + } + + /// returns true when the current Service instance is in foreground mode. + Future isForegroundService() async { + final result = await _channel.invokeMethod('isForegroundMode'); + return result ?? false; + } + + Future setAutoStartOnBootMode(bool value) async { + await _channel.invokeMethod("setAutoStartOnBootMode", { + "value": value, + }); + } + + Future openApp() async { + final result = await _channel.invokeMethod('openApp'); + return result ?? false; + } +} diff --git a/packages/flutter_background_service_android/melos_flutter_background_service_android.iml b/packages/flutter_background_service_android/melos_flutter_background_service_android.iml new file mode 100644 index 00000000..87149cbb --- /dev/null +++ b/packages/flutter_background_service_android/melos_flutter_background_service_android.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/flutter_background_service_android/pubspec.yaml b/packages/flutter_background_service_android/pubspec.yaml new file mode 100644 index 00000000..1d650a7e --- /dev/null +++ b/packages/flutter_background_service_android/pubspec.yaml @@ -0,0 +1,63 @@ +name: flutter_background_service_android +description: A flutter plugin for executing dart code continously even application closed. +version: 6.3.1 +repository: https://github.com/ekasetiawans/flutter_background_service + +environment: + sdk: ">=2.17.5 <4.0.0" + flutter: ">=3.0.0" + +dependencies: + flutter: + sdk: flutter + + flutter_background_service_platform_interface: ^5.1.2 +dev_dependencies: + flutter_test: + sdk: flutter + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: + # This section identifies this Flutter project as a plugin project. + # The 'pluginClass' and Android 'package' identifiers should not ordinarily + # be modified. They are used by the tooling to maintain consistency when + # adding or updating assets for this project. + plugin: + implements: flutter_background_service + platforms: + android: + package: id.flutter.flutter_background_service + pluginClass: FlutterBackgroundServicePlugin + dartPluginClass: FlutterBackgroundServiceAndroid + # To add assets to your plugin package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware. + # To add custom fonts to your plugin package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/flutter_background_service_android/test/flutter_background_service_test.dart b/packages/flutter_background_service_android/test/flutter_background_service_test.dart new file mode 100644 index 00000000..ab73b3a2 --- /dev/null +++ b/packages/flutter_background_service_android/test/flutter_background_service_test.dart @@ -0,0 +1 @@ +void main() {} diff --git a/packages/flutter_background_service_ios/.gitignore b/packages/flutter_background_service_ios/.gitignore new file mode 100644 index 00000000..899ae641 --- /dev/null +++ b/packages/flutter_background_service_ios/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +.dart_tool/ + +.packages +.pub/ + +build/ +pubspec.lock +.idea/ diff --git a/packages/flutter_background_service_ios/.metadata b/packages/flutter_background_service_ios/.metadata new file mode 100644 index 00000000..669304cf --- /dev/null +++ b/packages/flutter_background_service_ios/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 216dee60c0cc9449f0b29bcf922974d612263e24 + channel: stable + +project_type: plugin diff --git a/packages/flutter_background_service_ios/.vscode/settings.json b/packages/flutter_background_service_ios/.vscode/settings.json new file mode 100644 index 00000000..7f69797d --- /dev/null +++ b/packages/flutter_background_service_ios/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dart.runPubGetOnPubspecChanges": false +} \ No newline at end of file diff --git a/packages/flutter_background_service_ios/CHANGELOG.md b/packages/flutter_background_service_ios/CHANGELOG.md new file mode 100644 index 00000000..2e871649 --- /dev/null +++ b/packages/flutter_background_service_ios/CHANGELOG.md @@ -0,0 +1,300 @@ +## 5.0.3 + + - Update a dependency to the latest release. + +## 5.0.2 + + - Update a dependency to the latest release. + +## 5.0.1 + + - Update a dependency to the latest release. + +## 5.0.0 + +> Note: This release has breaking changes. + + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **REFACTOR**: update BGTaskScheduler flow. ([414bb21b](https://github.com/ekasetiawans/flutter_background_service/commit/414bb21b4d0af6112491fb81ee3246b7ef8a5c5b)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + - **PERF**: cancel old schedule. ([bfca5773](https://github.com/ekasetiawans/flutter_background_service/commit/bfca577324345f64faca562e32bad42ed16e92b4)) + - **FIX**: ios onBackground. ([0b1101be](https://github.com/ekasetiawans/flutter_background_service/commit/0b1101befa66f5d1f200c6a999f7e55c876f2a10)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FIX**: handle null safety. ([77513387](https://github.com/ekasetiawans/flutter_background_service/commit/775133879a1693154cf14181c3ac780aa7001710)) + - **FIX**: added pragma vm:entry-point to ios. ([7b44a2a4](https://github.com/ekasetiawans/flutter_background_service/commit/7b44a2a4ae977bd723874900eca689435989cfcd)) + - **FIX**: swift compile error. ([b75128ad](https://github.com/ekasetiawans/flutter_background_service/commit/b75128ad3100b4e505e4a3f8a037b07b9be547ad)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + - **FEAT**: onForeground and onBackground now optional. ([9dfcc4d4](https://github.com/ekasetiawans/flutter_background_service/commit/9dfcc4d4f4fea0f3b8ca0fbb47e3d127af3bc68d)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +## 4.0.0 + +> Note: This release has breaking changes. + + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **REFACTOR**: update BGTaskScheduler flow. ([414bb21b](https://github.com/ekasetiawans/flutter_background_service/commit/414bb21b4d0af6112491fb81ee3246b7ef8a5c5b)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + - **PERF**: cancel old schedule. ([bfca5773](https://github.com/ekasetiawans/flutter_background_service/commit/bfca577324345f64faca562e32bad42ed16e92b4)) + - **FIX**: ios onBackground. ([0b1101be](https://github.com/ekasetiawans/flutter_background_service/commit/0b1101befa66f5d1f200c6a999f7e55c876f2a10)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FIX**: handle null safety. ([77513387](https://github.com/ekasetiawans/flutter_background_service/commit/775133879a1693154cf14181c3ac780aa7001710)) + - **FIX**: added pragma vm:entry-point to ios. ([7b44a2a4](https://github.com/ekasetiawans/flutter_background_service/commit/7b44a2a4ae977bd723874900eca689435989cfcd)) + - **FIX**: swift compile error. ([b75128ad](https://github.com/ekasetiawans/flutter_background_service/commit/b75128ad3100b4e505e4a3f8a037b07b9be547ad)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + - **FEAT**: onForeground and onBackground now optional. ([9dfcc4d4](https://github.com/ekasetiawans/flutter_background_service/commit/9dfcc4d4f4fea0f3b8ca0fbb47e3d127af3bc68d)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +## 3.0.0 + +> Note: This release has breaking changes. + + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + +## 2.4.0 + + - **FEAT**: onForeground and onBackground now optional. ([9dfcc4d4](https://github.com/ekasetiawans/flutter_background_service/commit/9dfcc4d4f4fea0f3b8ca0fbb47e3d127af3bc68d)) + +## 2.3.1 + + - **REFACTOR**: remove unused methods. ([ea79ceda](https://github.com/ekasetiawans/flutter_background_service/commit/ea79cedac08089a3d6dafb8d7c785d73b753f80c)) + - **PERF**: improve handle app refresh ios. ([48e333d7](https://github.com/ekasetiawans/flutter_background_service/commit/48e333d708cb8296c8e6bf1bb151c7cbd95ea7ee)) + +## 2.3.0 + + - **REFACTOR**: split code into separate class. ([678226ba](https://github.com/ekasetiawans/flutter_background_service/commit/678226ba08966303713faa718f5a9b46e448c5d1)) + - **PERF**: cancel old schedule. ([bfca5773](https://github.com/ekasetiawans/flutter_background_service/commit/bfca577324345f64faca562e32bad42ed16e92b4)) + - **FIX**: ios onBackground. ([0b1101be](https://github.com/ekasetiawans/flutter_background_service/commit/0b1101befa66f5d1f200c6a999f7e55c876f2a10)) + - **FIX**: ios onBackground. ([4eb6b70d](https://github.com/ekasetiawans/flutter_background_service/commit/4eb6b70d005d43079fa53989a1352ae153ea03ae)) + - **FEAT**: allow using custom task identifier. ([555a0618](https://github.com/ekasetiawans/flutter_background_service/commit/555a06182230c126c7f0a43f6e94317e62ccb6c3)) + +## 2.2.5 + + - **FIX**: handle null safety. ([77513387](https://github.com/ekasetiawans/flutter_background_service/commit/775133879a1693154cf14181c3ac780aa7001710)) + +## 2.2.4 + + - Update a dependency to the latest release. + +## 2.2.3 + + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + +## 2.2.2 + + - Update a dependency to the latest release. + +## 2.2.1 + + - Update a dependency to the latest release. + +## 2.2.0 + + - **FIX**: added pragma vm:entry-point to ios. ([7b44a2a4](https://github.com/ekasetiawans/flutter_background_service/commit/7b44a2a4ae977bd723874900eca689435989cfcd)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + +## 2.1.0 + + - **FEAT**: automatically register plugins. ([3a0d0d53](https://github.com/ekasetiawans/flutter_background_service/commit/3a0d0d53110cdaf92caf4f329cd80034121c9ea6)) + +## 2.0.0 + + - Graduate package to a stable release. See pre-releases prior to this version for changelog entries. + +## 2.0.0-dev.2 + + - **FIX**: swift compile error. ([b75128ad](https://github.com/ekasetiawans/flutter_background_service/commit/b75128ad3100b4e505e4a3f8a037b07b9be547ad)) + +## 2.0.0-dev.1 + + - **REFACTOR**: update BGTaskScheduler flow. ([414bb21b](https://github.com/ekasetiawans/flutter_background_service/commit/414bb21b4d0af6112491fb81ee3246b7ef8a5c5b)) + +## 2.0.0-dev.0 + +> Note: This release has breaking changes. + + - **BREAKING** **FEAT**: implement new concept. ([c8ce9c0b](https://github.com/ekasetiawans/flutter_background_service/commit/c8ce9c0bab82137dea031af124b84510286661f7)) + +## 1.0.2 + + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + +## 1.0.1 + + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + +## 0.0.2 + + - **FEAT**: migrate to plugin platform interface. ([70e08ff0](https://github.com/ekasetiawans/flutter_background_service/commit/70e08ff03232c31946cc8eb7896f69c830f23322)) + +## 0.0.1+4 + + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + +## 0.0.1+3 + + - **FIX**: podspec. ([b46f9a3f](https://github.com/ekasetiawans/flutter_background_service/commit/b46f9a3f425f66e6bda34650e713da299f922a73)) + +## 0.0.1+2 + + - Update a dependency to the latest release. + +## 0.0.1+1 + + - **REFACTOR**: initialize melos. + +## 0.2.6 +* FIX: (Android) flutter initialization +## 0.2.5 +* FIX: (iOS) using other plugins +## 0.2.4 +* FIX: (Android) run service background when charger not connected and screen lock (#92) +## 0.2.3 +* ADDED: Using `BGTaskScheduler` on iOS 13. See readme for configuration. +## 0.2.2 +* ADDED: `autoStart` to `IosConfiguration` +## 0.2.1 +* UPDATE README +* UPDATE: Flutter Version Constraint +## 0.2.0+1 +* UPDATE README + +## 0.2.0 +* [BREAKING]: FlutterBackgroundService.initialize renamed to FlutterBackgroundService.configure +* [BREAKING]: use FlutterBackgroundService.start to start or restart after you call stopService. +* [ADDED]: IOS Background fetch is now supported you have to enable background fetch from xcode. +## 0.1.7 + +* Fix : cannot start service on android 12 +* Fix : not started on boot completed +## 0.1.6 + +* Android 12 Compatibility Changes +## 0.1.5 + +* Rollback foreground notification importance +## 0.1.4 + +* fixes UnsatisfiedLinkError when running as foreground service with autostart #32 +## 0.1.3 + +* Fix notification not showing on android 7 and prior (Issue #26) +## 0.1.2 + +* Open app from notification (Issue #30) +## 0.1.1 + +* Fix #29 (DartVM not terminated when service stop) + +## 0.1.0 + +* Bump flutter 2 + +## 0.1.0-nullsafety.2 + +* Fix #23 + +## 0.1.0-nullsafety.1 + +* Added isServiceRunning on iOS (issue #19) + +## 0.1.0-nullsafety.0 + +* Added support to nullsafety + +## 0.0.1+18 + +* Added stopService Method(Currently Works on Android Only). + +## 0.0.1+17 + +* Add preference autoStart on Boot, default is true. + +## 0.0.1+16 + +* Set Foreground Mode to false will remove notification. BugFix #4. + +## 0.0.1+15 + +* Add ability to change Background or Foreground mode (Android Only) + +## 0.0.1+14 + +* Bugfix BootReceiver + +## 0.0.1+13 + +* Update example for iOS support. + +## 0.0.1+12 + +* Start service immediately after initialize + +## 0.0.1+11 + +* iOS + +## 0.0.1+10 + +* bug fix + +## 0.0.1+9 + +* bug fix + +## 0.0.1+8 + +* bug fix + +## 0.0.1+7 + +* Add ability to send data from UI to Service + +## 0.0.1+6 + +* Improve stability + +## 0.0.1+5 + +* Add ability to send data from service to UI + +## 0.0.1+4 + +* Update README + +## 0.0.1+3 + +* Add ability to change notification info (Android foreground service) + +## 0.0.1+2 + +* Fix android missing plugin implementation + +## 0.0.1+1 + +* Fix android build + +## 0.0.1 + +* TODO: Describe initial release. \ No newline at end of file diff --git a/packages/flutter_background_service_ios/LICENSE b/packages/flutter_background_service_ios/LICENSE new file mode 100644 index 00000000..0b8db9ec --- /dev/null +++ b/packages/flutter_background_service_ios/LICENSE @@ -0,0 +1,7 @@ +Copyright 2022 Eka Setiawan Saputra + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/flutter_background_service_ios/README.md b/packages/flutter_background_service_ios/README.md new file mode 100644 index 00000000..04690e6b --- /dev/null +++ b/packages/flutter_background_service_ios/README.md @@ -0,0 +1,11 @@ +# flutter\_background\_service\_ios + +The iOS implementation of [`flutter_background_service`][1]. + +## Usage + +This package is [endorsed][2], which means you can simply use `flutter_background_service` +normally. This package will be automatically included in your app when you do. + +[1]: https://pub.dev/packages/flutter_background_service +[2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin \ No newline at end of file diff --git a/packages/flutter_background_service_ios/flutter_background_service.iml b/packages/flutter_background_service_ios/flutter_background_service.iml new file mode 100644 index 00000000..429df7da --- /dev/null +++ b/packages/flutter_background_service_ios/flutter_background_service.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ios/.gitignore b/packages/flutter_background_service_ios/ios/.gitignore similarity index 100% rename from ios/.gitignore rename to packages/flutter_background_service_ios/ios/.gitignore diff --git a/ios/Assets/.gitkeep b/packages/flutter_background_service_ios/ios/Assets/.gitkeep similarity index 100% rename from ios/Assets/.gitkeep rename to packages/flutter_background_service_ios/ios/Assets/.gitkeep diff --git a/ios/Classes/FlutterBackgroundServicePlugin.h b/packages/flutter_background_service_ios/ios/Classes/FlutterBackgroundServicePlugin.h similarity index 68% rename from ios/Classes/FlutterBackgroundServicePlugin.h rename to packages/flutter_background_service_ios/ios/Classes/FlutterBackgroundServicePlugin.h index da647bc2..d4dbacc0 100644 --- a/ios/Classes/FlutterBackgroundServicePlugin.h +++ b/packages/flutter_background_service_ios/ios/Classes/FlutterBackgroundServicePlugin.h @@ -1,4 +1,5 @@ #import @interface FlutterBackgroundServicePlugin : NSObject ++ (void)registerEngine:(FlutterEngine*)engine; @end diff --git a/packages/flutter_background_service_ios/ios/Classes/FlutterBackgroundServicePlugin.m b/packages/flutter_background_service_ios/ios/Classes/FlutterBackgroundServicePlugin.m new file mode 100644 index 00000000..7b7238e3 --- /dev/null +++ b/packages/flutter_background_service_ios/ios/Classes/FlutterBackgroundServicePlugin.m @@ -0,0 +1,33 @@ +#import "FlutterBackgroundServicePlugin.h" +#if __has_include() +#import +#else +// Support project import fallback if the generated compatibility header +// is not copied when this plugin is created as a library. +// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816 +#import "flutter_background_service_ios-Swift.h" +#endif + +@interface GeneratedPluginRegistrant : NSObject ++ (void)registerWithRegistry:(NSObject*)registry; +@end + + +@implementation FlutterBackgroundServicePlugin ++ (void)registerWithRegistrar:(NSObject*)registrar { + [SwiftFlutterBackgroundServicePlugin registerWithRegistrar:registrar]; +} + ++ (void)setPluginRegistrantCallback:(FlutterPluginRegistrantCallback)callback { + [SwiftFlutterBackgroundServicePlugin setPluginRegistrantCallback:callback]; +} + ++ (nullable Class)lookupGeneratedPluginRegistrant { + NSString* classNameToCompare = @"GeneratedPluginRegistrant"; + return NSClassFromString(classNameToCompare); +} + ++ (void)registerEngine:(FlutterEngine*)engine { + [[FlutterBackgroundServicePlugin lookupGeneratedPluginRegistrant] registerWithRegistry:engine]; +} +@end diff --git a/packages/flutter_background_service_ios/ios/Classes/SwiftFlutterBackgroundServicePlugin.swift b/packages/flutter_background_service_ios/ios/Classes/SwiftFlutterBackgroundServicePlugin.swift new file mode 100644 index 00000000..358ebb5f --- /dev/null +++ b/packages/flutter_background_service_ios/ios/Classes/SwiftFlutterBackgroundServicePlugin.swift @@ -0,0 +1,367 @@ +import Flutter +import UIKit +import AVKit +import BackgroundTasks + +public class SwiftFlutterBackgroundServicePlugin: FlutterPluginAppLifeCycleDelegate, FlutterPlugin { + public static var taskIdentifier = "dev.flutter.background.refresh" + // For testing, run app, bring app to background to schedule the task + // Pause debug in XCODE, then execute: + // e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"dev.flutter.background.refresh"] + // in Outputs log after (lldb) + // Resume debugger + + var mainChannel: FlutterMethodChannel? = nil + + public override func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) -> Bool { + + let defaults = UserDefaults.standard + let callbackHandle = defaults.object(forKey: "background_callback_handle") as? Int64 + if (callbackHandle == nil){ + print("Background handler is disabled") + completionHandler(.noData) + return true + } + + // execute callback handle + + let worker = FlutterBackgroundFetchWorker(task: completionHandler) + worker.onCompleted = { + print("Background Fetch Completed") + } + worker.run() + return true + } + + public override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [AnyHashable : Any] = [:]) -> Bool { + UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum) + if #available(iOS 13.0, *) { + SwiftFlutterBackgroundServicePlugin.registerTaskIdentifier(taskIdentifier: SwiftFlutterBackgroundServicePlugin.taskIdentifier) + } + + return true + } + + public func applicationDidEnterBackground(_ application: UIApplication) { + if #available(iOS 13.0, *){ + SwiftFlutterBackgroundServicePlugin.scheduleAppRefresh() + } + } + + @available(iOS 13.0, *) + public static func registerTaskIdentifier(taskIdentifier: String) { + BGTaskScheduler.shared.register(forTaskWithIdentifier: taskIdentifier, using: nil) { task in + self.handleAppRefresh(task: task as! BGAppRefreshTask) + } + } + + @available(iOS 13.0, *) + private static func scheduleAppRefresh() { + let request = BGAppRefreshTaskRequest(identifier: SwiftFlutterBackgroundServicePlugin.taskIdentifier) + request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60) + + do { + // cancel old schedule + BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: SwiftFlutterBackgroundServicePlugin.taskIdentifier) + + try BGTaskScheduler.shared.submit(request) + } catch { + print("Could not schedule app refresh: \(error)") + } + } + + @available(iOS 13.0, *) + private static func handleAppRefresh(task: BGAppRefreshTask) { + let defaults = UserDefaults.standard + let callbackHandle = defaults.object(forKey: "background_callback_handle") as? Int64 + if (callbackHandle == nil){ + print("Background handler is disabled") + return + } + + let operationQueue = OperationQueue() + let operation = FlutterBackgroundRefreshAppOperation( + task: task + ) + + operation.completionBlock = { + scheduleAppRefresh() + } + + operationQueue.addOperation(operation) + } + + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel( + name: "id.flutter/background_service_ios", + binaryMessenger: registrar.messenger(), + codec: FlutterJSONMethodCodec()) + + let instance = SwiftFlutterBackgroundServicePlugin() + instance.mainChannel = channel + + registrar.addMethodCallDelegate(instance, channel: channel) + registrar.addApplicationDelegate(instance) + } + + private func autoStart(isForeground: Bool) { + let defaults = UserDefaults.standard + let autoStart = defaults.bool(forKey: "auto_start") + if (autoStart) { + self.runForegroundWorker() + } + } + + fileprivate var foregroundWorker: FlutterForegroundWorker? = nil + private func runForegroundWorker(){ + if (foregroundWorker != nil){ + return + } + + let defaults = UserDefaults.standard + let callbackHandle = defaults.object(forKey: "foreground_callback_handle") as? Int64 + if (callbackHandle == nil){ + print("Foreground service is disabled") + return + } + + foregroundWorker = FlutterForegroundWorker(mainChannel: self.mainChannel!) + foregroundWorker?.onTerminated = { + self.foregroundWorker = nil + } + foregroundWorker?.run() + } + + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + if (call.method == "configure") { + let args = call.arguments as? Dictionary + let foregroundCallbackHandleID = args?["foreground_handle"] as? NSNumber + let backgroundCallbackHandleID = args?["background_handle"] as? NSNumber + let autoStart = args?["auto_start"] as? Bool ?? true + + let defaults = UserDefaults.standard + defaults.set(foregroundCallbackHandleID?.int64Value, forKey: "foreground_callback_handle") + defaults.set(backgroundCallbackHandleID?.int64Value, forKey: "background_callback_handle") + defaults.set(autoStart, forKey: "auto_start") + + if (autoStart && (foregroundCallbackHandleID != nil)){ + self.autoStart(isForeground: true) + } + + result(true) + return + } + + if (call.method == "start") { + runForegroundWorker() + result(true) + } + + if (call.method == "sendData") { + self.foregroundWorker?.onReceivedData(data: call.arguments) + result(true); + } + + if (call.method == "isServiceRunning") { + let value = self.foregroundWorker != nil; + result(value); + return; + } + } +} + +@available(iOS 13, *) +class FlutterBackgroundRefreshAppOperation: Operation { + var task: BGAppRefreshTask + fileprivate var worker: FlutterBackgroundRefreshAppWorker? + + init(task: BGAppRefreshTask) { + self.task = task + } + + override func main() { + let semaphore = DispatchSemaphore(value: 0) + + DispatchQueue.main.async { + self.worker = FlutterBackgroundRefreshAppWorker(task: self.task) + self.worker?.onCompleted = { + semaphore.signal() + } + + self.task.expirationHandler = { + self.worker?.cancel() + } + + self.worker?.run() + } + + semaphore.wait() + } +} + +typealias VoidInputVoidReturnBlock = () -> Void + +@available(iOS 13, *) +private class FlutterBackgroundRefreshAppWorker { + let entrypointName = "backgroundEntrypoint" + let uri = "package:flutter_background_service_ios/flutter_background_service_ios.dart" + let engine = FlutterEngine(name: "BackgroundHandleFlutterEngine") + + var onCompleted: VoidInputVoidReturnBlock? + var task: BGAppRefreshTask + var channel: FlutterMethodChannel? + + init(task: BGAppRefreshTask){ + self.task = task + } + + public func run() { + let defaults = UserDefaults.standard + let callbackHandle = defaults.object(forKey: "background_callback_handle") as? Int64 + if (callbackHandle == nil){ + print("No callback handle for background") + return + } + + let isRunning = engine.run(withEntrypoint: entrypointName, libraryURI: uri, initialRoute: nil, entrypointArgs: [String(callbackHandle!)]) + + if (isRunning){ + FlutterBackgroundServicePlugin.register(engine) + + let binaryMessenger = engine.binaryMessenger + channel = FlutterMethodChannel(name: "id.flutter/background_service_ios_bg", binaryMessenger: binaryMessenger, codec: FlutterJSONMethodCodec()) + channel?.setMethodCallHandler(handleMethodCall) + } + } + + public func cancel(){ + DispatchQueue.main.async { + self.engine.destroyContext() + } + + self.task.setTaskCompleted(success: false) + self.onCompleted?() + } + + private func handleMethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + if (call.method == "setBackgroundFetchResult") { + let result = call.arguments as? Bool ?? false + self.task.setTaskCompleted(success: result) + + DispatchQueue.main.async { + self.engine.destroyContext() + } + + self.onCompleted?() + print("Flutter Background Service Completed") + } + } +} + +private class FlutterBackgroundFetchWorker { + let entrypointName = "backgroundEntrypoint" + let uri = "package:flutter_background_service_ios/flutter_background_service_ios.dart" + let engine = FlutterEngine(name: "BackgroundHandleFlutterEngine") + + var onCompleted: VoidInputVoidReturnBlock? + var task: ((UIBackgroundFetchResult) -> Void) + var channel: FlutterMethodChannel? + + init(task: @escaping (UIBackgroundFetchResult) -> Void){ + self.task = task + } + + public func run() { + let defaults = UserDefaults.standard + let callbackHandle = defaults.object(forKey: "background_callback_handle") as? Int64 + if (callbackHandle == nil){ + print("No callback handle for background") + return + } + + let isRunning = engine.run(withEntrypoint: entrypointName, libraryURI: uri, initialRoute: nil, entrypointArgs: [String(callbackHandle!)]) + + if (isRunning){ + FlutterBackgroundServicePlugin.register(engine) + + let binaryMessenger = engine.binaryMessenger + channel = FlutterMethodChannel(name: "id.flutter/background_service_ios_bg", binaryMessenger: binaryMessenger, codec: FlutterJSONMethodCodec()) + channel?.setMethodCallHandler(handleMethodCall) + } + } + + public func cancel(){ + self.engine.destroyContext() + self.task(.failed) + self.onCompleted?() + } + + private func handleMethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + if (call.method == "setBackgroundFetchResult") { + let result = call.arguments as? Bool ?? false + + if (result) { + self.task(.newData) + } else { + self.task(.noData) + } + + self.engine.destroyContext() + self.onCompleted?() + print("Flutter Background Service Completed") + } + } +} + +private class FlutterForegroundWorker { + let entrypointName = "foregroundEntrypoint" + let uri = "package:flutter_background_service_ios/flutter_background_service_ios.dart" + let engine = FlutterEngine(name: "ForegroundHandleFlutterEngine") + + var channel: FlutterMethodChannel? + var mainChannel: FlutterMethodChannel + var onTerminated: VoidInputVoidReturnBlock? + + init(mainChannel: FlutterMethodChannel){ + self.mainChannel = mainChannel + } + + public func run() { + let defaults = UserDefaults.standard + let callbackHandle = defaults.object(forKey: "foreground_callback_handle") as? Int64 + if (callbackHandle == nil){ + print("No callback handle for foreground") + return + } + + let isRunning = engine.run(withEntrypoint: entrypointName, libraryURI: uri, initialRoute: nil, entrypointArgs: [String(callbackHandle!)]) + + if (isRunning){ + FlutterBackgroundServicePlugin.register(engine) + + let binaryMessenger = engine.binaryMessenger + channel = FlutterMethodChannel(name: "id.flutter/background_service_ios_bg", binaryMessenger: binaryMessenger, codec: FlutterJSONMethodCodec()) + channel?.setMethodCallHandler(handleMethodCall) + } + } + + public func onReceivedData(data: Any?) { + self.channel?.invokeMethod("onReceiveData", arguments: data) + } + + private func handleMethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + if (call.method == "sendData") { + self.mainChannel.invokeMethod("onReceiveData", arguments: call.arguments) + result(true); + return; + } + + if (call.method == "stopService") { + self.engine.destroyContext() + result(true) + self.onTerminated?() + return; + } + } +} diff --git a/ios/flutter_background_service.podspec b/packages/flutter_background_service_ios/ios/flutter_background_service_ios.podspec similarity index 90% rename from ios/flutter_background_service.podspec rename to packages/flutter_background_service_ios/ios/flutter_background_service_ios.podspec index 6c40347e..be1423d3 100644 --- a/ios/flutter_background_service.podspec +++ b/packages/flutter_background_service_ios/ios/flutter_background_service_ios.podspec @@ -3,8 +3,8 @@ # Run `pod lib lint flutter_background_service.podspec' to validate before publishing. # Pod::Spec.new do |s| - s.name = 'flutter_background_service' - s.version = '0.0.1' + s.name = 'flutter_background_service_ios' + s.version = '0.0.3' s.summary = 'A new flutter plugin project.' s.description = <<-DESC A new flutter plugin project. diff --git a/packages/flutter_background_service_ios/lib/flutter_background_service_ios.dart b/packages/flutter_background_service_ios/lib/flutter_background_service_ios.dart new file mode 100644 index 00000000..ea92fabb --- /dev/null +++ b/packages/flutter_background_service_ios/lib/flutter_background_service_ios.dart @@ -0,0 +1,173 @@ +library flutter_background_service_ios; + +import 'dart:async'; +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_background_service_platform_interface/flutter_background_service_platform_interface.dart'; + +@pragma('vm:entry-point') +Future foregroundEntrypoint(List args) async { + WidgetsFlutterBinding.ensureInitialized(); + final service = IOSServiceInstance._(); + final int handle = int.parse(args.first); + final callbackHandle = CallbackHandle.fromRawHandle(handle); + final onStart = PluginUtilities.getCallbackFromHandle(callbackHandle); + if (onStart != null) { + onStart(service); + } +} + +@pragma('vm:entry-point') +Future backgroundEntrypoint(List args) async { + WidgetsFlutterBinding.ensureInitialized(); + final service = IOSServiceInstance._(); + final int handle = int.parse(args.first); + final callbackHandle = CallbackHandle.fromRawHandle(handle); + final onStart = PluginUtilities.getCallbackFromHandle(callbackHandle) + as FutureOr Function(ServiceInstance instance)?; + if (onStart != null) { + final result = await onStart(service); + await service._setBackgroundFetchResult(result); + } +} + +class FlutterBackgroundServiceIOS extends FlutterBackgroundServicePlatform { + /// Registers this class as the default instance of [FlutterBackgroundServicePlatform]. + static void registerWith() { + FlutterBackgroundServicePlatform.instance = FlutterBackgroundServiceIOS(); + } + + static const MethodChannel _channel = const MethodChannel( + 'id.flutter/background_service_ios', + JSONMethodCodec(), + ); + + Future _handle(MethodCall call) async { + switch (call.method) { + case "onReceiveData": + _streamController.sink.add(call.arguments); + break; + default: + } + + return true; + } + + Future start() async { + final result = await _channel.invokeMethod('start'); + return result ?? false; + } + + Future configure({ + required IosConfiguration iosConfiguration, + required AndroidConfiguration androidConfiguration, + }) async { + _channel.setMethodCallHandler(_handle); + + final CallbackHandle? foregroundHandle = + iosConfiguration.onForeground == null + ? null + : PluginUtilities.getCallbackHandle(iosConfiguration.onForeground!); + + final CallbackHandle? backgroundHandle = + iosConfiguration.onBackground == null + ? null + : PluginUtilities.getCallbackHandle(iosConfiguration.onBackground!); + + final result = await _channel.invokeMethod( + "configure", + { + "background_handle": backgroundHandle?.toRawHandle(), + "foreground_handle": foregroundHandle?.toRawHandle(), + "auto_start": iosConfiguration.autoStart, + }, + ); + + return result ?? false; + } + + Future isServiceRunning() async { + var result = await _channel.invokeMethod("isServiceRunning"); + return result ?? false; + } + + final _streamController = StreamController.broadcast(sync: true); + + void dispose() { + _streamController.close(); + } + + @override + void invoke(String method, [Map? args]) { + _channel.invokeMethod("sendData", { + 'method': method, + 'args': args, + }); + } + + @override + Stream?> on(String method) { + return _streamController.stream.transform( + StreamTransformer.fromHandlers( + handleData: (data, sink) { + if (data['method'] == method) { + sink.add(data['args']); + } + }, + ), + ); + } +} + +class IOSServiceInstance extends ServiceInstance { + static const MethodChannel _channel = const MethodChannel( + 'id.flutter/background_service_ios_bg', + JSONMethodCodec(), + ); + + IOSServiceInstance._() { + _channel.setMethodCallHandler(_handleMethodCall); + } + + final _controller = StreamController.broadcast(sync: true); + Future _handleMethodCall(MethodCall call) async { + switch (call.method) { + case "onReceiveData": + _controller.sink.add(call.arguments); + break; + default: + } + } + + @override + void invoke(String method, [Map? args]) { + _channel.invokeMethod('sendData', { + 'method': method, + 'args': args, + }); + } + + @override + Future stopSelf() async { + await _channel.invokeMethod("stopService"); + } + + @override + Stream?> on(String method) { + return _controller.stream.transform( + StreamTransformer.fromHandlers( + handleData: (data, sink) { + if (data['method'] == method) { + sink.add(data['args']); + } + }, + ), + ); + } + + Future _setBackgroundFetchResult(bool value) async { + await _channel.invokeMethod('setBackgroundFetchResult', value); + } +} diff --git a/packages/flutter_background_service_ios/melos_flutter_background_service_ios.iml b/packages/flutter_background_service_ios/melos_flutter_background_service_ios.iml new file mode 100644 index 00000000..87149cbb --- /dev/null +++ b/packages/flutter_background_service_ios/melos_flutter_background_service_ios.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/flutter_background_service_ios/pubspec.yaml b/packages/flutter_background_service_ios/pubspec.yaml new file mode 100644 index 00000000..502f1b3c --- /dev/null +++ b/packages/flutter_background_service_ios/pubspec.yaml @@ -0,0 +1,62 @@ +name: flutter_background_service_ios +description: A flutter plugin for executing dart code continously even application closed. +version: 5.0.3 +repository: https://github.com/ekasetiawans/flutter_background_service + +environment: + sdk: ">=2.17.5 <4.0.0" + flutter: ">=3.0.0" + +dependencies: + flutter: + sdk: flutter + + flutter_background_service_platform_interface: ^5.1.2 +dev_dependencies: + flutter_test: + sdk: flutter + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter. +flutter: + # This section identifies this Flutter project as a plugin project. + # The 'pluginClass' and Android 'package' identifiers should not ordinarily + # be modified. They are used by the tooling to maintain consistency when + # adding or updating assets for this project. + plugin: + implements: flutter_background_service + platforms: + ios: + pluginClass: FlutterBackgroundServicePlugin + dartPluginClass: FlutterBackgroundServiceIOS + # To add assets to your plugin package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware. + # To add custom fonts to your plugin package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/flutter_background_service_ios/test/flutter_background_service_test.dart b/packages/flutter_background_service_ios/test/flutter_background_service_test.dart new file mode 100644 index 00000000..ab73b3a2 --- /dev/null +++ b/packages/flutter_background_service_ios/test/flutter_background_service_test.dart @@ -0,0 +1 @@ +void main() {} diff --git a/packages/flutter_background_service_platform_interface/.gitignore b/packages/flutter_background_service_platform_interface/.gitignore new file mode 100644 index 00000000..9be145fd --- /dev/null +++ b/packages/flutter_background_service_platform_interface/.gitignore @@ -0,0 +1,29 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/packages/flutter_background_service_platform_interface/.metadata b/packages/flutter_background_service_platform_interface/.metadata new file mode 100644 index 00000000..0bb64e4a --- /dev/null +++ b/packages/flutter_background_service_platform_interface/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 7e9793dee1b85a243edd0e06cb1658e98b077561 + channel: stable + +project_type: package diff --git a/packages/flutter_background_service_platform_interface/CHANGELOG.md b/packages/flutter_background_service_platform_interface/CHANGELOG.md new file mode 100644 index 00000000..f3cff4d5 --- /dev/null +++ b/packages/flutter_background_service_platform_interface/CHANGELOG.md @@ -0,0 +1,113 @@ +## 5.1.2 + + - **FIX**: fix lints. ([95186405](https://github.com/ekasetiawans/flutter_background_service/commit/95186405f2d60112ff83956bce345ebbbc332ad7)) + +## 5.1.1 + + - **FIX**: fix crash on android 14 after starting foreground service. ([4bdc46d9](https://github.com/ekasetiawans/flutter_background_service/commit/4bdc46d951febafbcbb2b118324cddc2b30ad752)) + +## 5.1.0 + + - **FEAT**: updated dependencies. ([e90ad787](https://github.com/ekasetiawans/flutter_background_service/commit/e90ad787b3a7b157aeeec3a45920839aafe2933d)) + +## 5.0.0 + +> Note: This release has breaking changes. + + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **FIX**: remove duplicated properties. ([891c2029](https://github.com/ekasetiawans/flutter_background_service/commit/891c20291df9612810035219af98d732d99d200c)) + - **FIX**: missing foregroundServiceNotificationId. ([e49f6137](https://github.com/ekasetiawans/flutter_background_service/commit/e49f613726120f144b04e2246c43360756d57e5b)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: method channel. ([1a1e3527](https://github.com/ekasetiawans/flutter_background_service/commit/1a1e3527465a4ede4c188b4e1aa51ce552e697c1)) + - **FEAT**: Updated configs. ([7af1961d](https://github.com/ekasetiawans/flutter_background_service/commit/7af1961def1625d7a5314812c1f794e327f53ce7)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: introduce ServiceInstance. ([425279b0](https://github.com/ekasetiawans/flutter_background_service/commit/425279b09378fbcd8e66295ce526f2c4f15d741c)) + - **BREAKING** **CHANGE**: supported only flutter 2.0.0 and newer. ([be0c32f8](https://github.com/ekasetiawans/flutter_background_service/commit/be0c32f8200dcce44ddce67461c333d6d0ef287c)) + +## 4.0.0 + +> Note: This release has breaking changes. + + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + - **REFACTOR**: initialize melos. ([00bf06da](https://github.com/ekasetiawans/flutter_background_service/commit/00bf06da1ca1f4554edaabbd108c59f34b02c611)) + - **FIX**: remove duplicated properties. ([891c2029](https://github.com/ekasetiawans/flutter_background_service/commit/891c20291df9612810035219af98d732d99d200c)) + - **FIX**: missing foregroundServiceNotificationId. ([e49f6137](https://github.com/ekasetiawans/flutter_background_service/commit/e49f613726120f144b04e2246c43360756d57e5b)) + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + - **FIX**: method channel. ([1a1e3527](https://github.com/ekasetiawans/flutter_background_service/commit/1a1e3527465a4ede4c188b4e1aa51ce552e697c1)) + - **FEAT**: Updated configs. ([7af1961d](https://github.com/ekasetiawans/flutter_background_service/commit/7af1961def1625d7a5314812c1f794e327f53ce7)) + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + - **BREAKING** **FEAT**: introduce ServiceInstance. ([425279b0](https://github.com/ekasetiawans/flutter_background_service/commit/425279b09378fbcd8e66295ce526f2c4f15d741c)) + - **BREAKING** **CHANGE**: supported only flutter 2.0.0 and newer. ([be0c32f8](https://github.com/ekasetiawans/flutter_background_service/commit/be0c32f8200dcce44ddce67461c333d6d0ef287c)) + +## 3.0.0 + +> Note: This release has breaking changes. + + - **BREAKING** **FEAT**: updated dependency constraints. ([97ef7977](https://github.com/ekasetiawans/flutter_background_service/commit/97ef7977ff9a2cb31b1e29593b3a9cc725d89e27)) + +## 2.2.0 + + - **FEAT**: Updated configs. ([7af1961d](https://github.com/ekasetiawans/flutter_background_service/commit/7af1961def1625d7a5314812c1f794e327f53ce7)) + +## 2.1.4 + + - **REFACTOR**: refactor java code. ([d7db0c09](https://github.com/ekasetiawans/flutter_background_service/commit/d7db0c092dcfc0af0bb8f1175ea82f3f0ccfe908)) + +## 2.1.3 + + - **DOCS**: update license. ([0c17e5de](https://github.com/ekasetiawans/flutter_background_service/commit/0c17e5dee091daa622470c8e3ba16c22ae03f8b3)) + +## 2.1.2 + + - **FIX**: remove duplicated properties. ([891c2029](https://github.com/ekasetiawans/flutter_background_service/commit/891c20291df9612810035219af98d732d99d200c)) + +## 2.1.1 + + - **FIX**: missing foregroundServiceNotificationId. ([e49f6137](https://github.com/ekasetiawans/flutter_background_service/commit/e49f613726120f144b04e2246c43360756d57e5b)) + +## 2.1.0 + + - **FEAT**: using entrypoint instead of dart callback and added initial notification info for android. ([b0fc8f32](https://github.com/ekasetiawans/flutter_background_service/commit/b0fc8f32d59fa582c37fcd6e2349fab32aac245b)) + +## 2.0.0 + + - Graduate package to a stable release. See pre-releases prior to this version for changelog entries. + +## 2.0.0-dev.0 + +> Note: This release has breaking changes. + + - **BREAKING** **FEAT**: introduce ServiceInstance. ([425279b0](https://github.com/ekasetiawans/flutter_background_service/commit/425279b09378fbcd8e66295ce526f2c4f15d741c)) + +## 1.0.2 + + - **DOCS**: readme link. ([1479b91c](https://github.com/ekasetiawans/flutter_background_service/commit/1479b91cd80d637335de1314a528bcf51ebb7c0f)) + +## 1.0.1 + + - **DOCS**: update README. ([fbf5e0ab](https://github.com/ekasetiawans/flutter_background_service/commit/fbf5e0abeeb9296ba32361b8af0a298ee9e71527)) + +## 0.0.1+3 + + - **FIX**: errors. ([13a6f841](https://github.com/ekasetiawans/flutter_background_service/commit/13a6f841f5d677ceb0010e8ba1bf9d7af53adbcf)) + +## 0.0.1+2 + + - **FIX**: method channel. ([1a1e3527](https://github.com/ekasetiawans/flutter_background_service/commit/1a1e3527465a4ede4c188b4e1aa51ce552e697c1)) + +## 0.0.1+1 + + - **REFACTOR**: initialize melos. + +## 0.0.1 + +* Initial release diff --git a/packages/flutter_background_service_platform_interface/LICENSE b/packages/flutter_background_service_platform_interface/LICENSE new file mode 100644 index 00000000..0b8db9ec --- /dev/null +++ b/packages/flutter_background_service_platform_interface/LICENSE @@ -0,0 +1,7 @@ +Copyright 2022 Eka Setiawan Saputra + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/flutter_background_service_platform_interface/README.md b/packages/flutter_background_service_platform_interface/README.md new file mode 100644 index 00000000..0212471a --- /dev/null +++ b/packages/flutter_background_service_platform_interface/README.md @@ -0,0 +1,26 @@ +# flutter_background_service_platform_interface + +A common platform interface for the [`flutter_background_service`][1] plugin. + +This interface allows platform-specific implementations of the `flutter_background_service` +plugin, as well as the plugin itself, to ensure they are supporting the +same interface. + +# Usage + +To implement a new platform-specific implementation of `flutter_background_service`, extend +[`FlutterBackgroundServicePlatform`][2] with an implementation that performs the +platform-specific behavior, and when you register your plugin, set the default +`FlutterBackgroundServicePlatform` by calling +`FlutterBackgroundServicePlatform.instance = MyPlatformPathProvider()`. + +# Note on breaking changes + +Strongly prefer non-breaking changes (such as adding a method to the interface) +over breaking changes for this package. + +See https://flutter.dev/go/platform-interface-breaking-changes for a discussion +on why a less-clean interface is preferable to a breaking change. + +[1]: ../ +[2]: lib/flutter_background_service_platform_interface.dart \ No newline at end of file diff --git a/packages/flutter_background_service_platform_interface/analysis_options.yaml b/packages/flutter_background_service_platform_interface/analysis_options.yaml new file mode 100644 index 00000000..a5744c1c --- /dev/null +++ b/packages/flutter_background_service_platform_interface/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/flutter_background_service_platform_interface/lib/flutter_background_service_platform_interface.dart b/packages/flutter_background_service_platform_interface/lib/flutter_background_service_platform_interface.dart new file mode 100644 index 00000000..e360ba87 --- /dev/null +++ b/packages/flutter_background_service_platform_interface/lib/flutter_background_service_platform_interface.dart @@ -0,0 +1,48 @@ +import 'dart:async'; + +import 'package:flutter_background_service_platform_interface/src/configs.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +export 'src/configs.dart'; + +abstract class Observable { + void invoke(String method, [Map? args]); + Stream?> on(String method); +} + +abstract class FlutterBackgroundServicePlatform extends PlatformInterface + implements Observable { + FlutterBackgroundServicePlatform() : super(token: _token); + static final Object _token = Object(); + + static FlutterBackgroundServicePlatform? _instance; + + static FlutterBackgroundServicePlatform get instance { + if (_instance == null) { + throw 'FlutterBackgroundService is currently supported for Android and iOS Platform only.'; + } + + return _instance!; + } + + /// Platform-specific plugins should set this with their own platform-specific + /// class that extends [FlutterBackgroundServicePlatform] when they register themselves. + static set instance(FlutterBackgroundServicePlatform instance) { + PlatformInterface.verify(instance, _token); + _instance = instance; + } + + Future configure({ + required IosConfiguration iosConfiguration, + required AndroidConfiguration androidConfiguration, + }); + + Future start(); + + Future isServiceRunning(); +} + +abstract class ServiceInstance implements Observable { + /// Stop the service + Future stopSelf(); +} diff --git a/packages/flutter_background_service_platform_interface/lib/src/configs.dart b/packages/flutter_background_service_platform_interface/lib/src/configs.dart new file mode 100644 index 00000000..fadeb3c6 --- /dev/null +++ b/packages/flutter_background_service_platform_interface/lib/src/configs.dart @@ -0,0 +1,81 @@ +import 'dart:async'; + +import 'package:flutter_background_service_platform_interface/flutter_background_service_platform_interface.dart'; + +class IosConfiguration { + /// must be a top level or static method + /// this method will be executed when app is in foreground + final Function(ServiceInstance service)? onForeground; + + /// must be a top level or static method + /// this method will be executed by background fetch + /// make sure you don't execute long running task there because of limitations on ios + /// recommended maximum executed duration is only 15-20 seconds. + final FutureOr Function(ServiceInstance service)? onBackground; + + /// whether service auto start after configure. + final bool autoStart; + + IosConfiguration({ + this.onForeground, + this.onBackground, + this.autoStart = true, + }); +} + +enum AndroidForegroundType { + camera, + connectedDevice, + dataSync, + health, + location, + mediaPlayback, + mediaProjection, + microphone, + phoneCall, + remoteMessaging, + shortService, + specialUse, + systemExempted +} + +class AndroidConfiguration { + /// must be a top level or static method + final Function(ServiceInstance service) onStart; + + /// whether service can start automatically after configure + final bool autoStart; + + /// whether service can start automatically on boot + final bool autoStartOnBoot; + + /// whether service is foreground or background mode + final bool isForegroundMode; + + /// notification content that will be shown on status bar when the background service is starting + /// defaults to "Preparing" + final String initialNotificationContent; + final String initialNotificationTitle; + + /// use custom notification channel id + /// you must to create the notification channel before you run configure() method. + final String? notificationChannelId; + + /// notification id will be used by foreground service + final int foregroundServiceNotificationId; + + /// foreground service types + final List? foregroundServiceTypes; + + AndroidConfiguration({ + required this.onStart, + this.autoStart = true, + this.autoStartOnBoot = true, + required this.isForegroundMode, + this.initialNotificationContent = 'Preparing', + this.initialNotificationTitle = 'Background Service', + this.notificationChannelId, + this.foregroundServiceNotificationId = 112233, + this.foregroundServiceTypes, + }); +} diff --git a/packages/flutter_background_service_platform_interface/pubspec.yaml b/packages/flutter_background_service_platform_interface/pubspec.yaml new file mode 100644 index 00000000..13fb9c1f --- /dev/null +++ b/packages/flutter_background_service_platform_interface/pubspec.yaml @@ -0,0 +1,57 @@ +name: flutter_background_service_platform_interface +description: A platform interface for flutter background service. +version: 5.1.2 +repository: https://github.com/ekasetiawans/flutter_background_service + +environment: + sdk: ">=2.17.5 <4.0.0" + flutter: ">=3.0.0" + +dependencies: + flutter: + sdk: flutter + + platform: ^3.1.0 + plugin_platform_interface: ^2.1.2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^4.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter. +# flutter: + + # To add assets to your package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware. + + # To add custom fonts to your package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/flutter_background_service_platform_interface/test/flutter_background_service_platform_interface_test.dart b/packages/flutter_background_service_platform_interface/test/flutter_background_service_platform_interface_test.dart new file mode 100644 index 00000000..ab73b3a2 --- /dev/null +++ b/packages/flutter_background_service_platform_interface/test/flutter_background_service_platform_interface_test.dart @@ -0,0 +1 @@ +void main() {} diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 00000000..da3f7d06 --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,342 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + ansi_styles: + dependency: transitive + description: + name: ansi_styles + sha256: "9c656cc12b3c27b17dd982b2cc5c0cfdfbdabd7bc8f3ae5e8542d9867b47ce8a" + url: "https://pub.dev" + source: hosted + version: "0.3.2+1" + args: + dependency: transitive + description: + name: args + sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6 + url: "https://pub.dev" + source: hosted + version: "2.6.0" + async: + dependency: transitive + description: + name: async + sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 + url: "https://pub.dev" + source: hosted + version: "2.12.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + charcode: + dependency: transitive + description: + name: charcode + sha256: fb0f1107cac15a5ea6ef0a6ef71a807b9e4267c713bb93e00e92d737cc8dbd8a + url: "https://pub.dev" + source: hosted + version: "1.4.0" + cli_launcher: + dependency: transitive + description: + name: cli_launcher + sha256: "5e7e0282b79e8642edd6510ee468ae2976d847a0a29b3916e85f5fa1bfe24005" + url: "https://pub.dev" + source: hosted + version: "0.3.1" + cli_util: + dependency: transitive + description: + name: cli_util + sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c + url: "https://pub.dev" + source: hosted + version: "0.4.2" + clock: + dependency: transitive + description: + name: clock + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + conventional_commit: + dependency: transitive + description: + name: conventional_commit + sha256: dec15ad1118f029c618651a4359eb9135d8b88f761aa24e4016d061cd45948f2 + url: "https://pub.dev" + source: hosted + version: "0.6.0+1" + file: + dependency: transitive + description: + name: file + sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 + url: "https://pub.dev" + source: hosted + version: "7.0.1" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + graphs: + dependency: transitive + description: + name: graphs + sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + http: + dependency: transitive + description: + name: http + sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 + url: "https://pub.dev" + source: hosted + version: "1.2.2" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "76d306a1c3afb33fe82e2bbacad62a61f409b5634c915fceb0d799de1a913360" + url: "https://pub.dev" + source: hosted + version: "4.1.1" + intl: + dependency: transitive + description: + name: intl + sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf + url: "https://pub.dev" + source: hosted + version: "0.19.0" + io: + dependency: transitive + description: + name: io + sha256: dfd5a80599cf0165756e3181807ed3e77daf6dd4137caaad72d0b7931597650b + url: "https://pub.dev" + source: hosted + version: "1.0.5" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 + url: "https://pub.dev" + source: hosted + version: "0.12.17" + melos: + dependency: "direct main" + description: + name: melos + sha256: a62abfa8c7826cec927f8585572bb9adf591be152150494d879ca2c75118809d + url: "https://pub.dev" + source: hosted + version: "6.2.0" + meta: + dependency: transitive + description: + name: meta + sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c + url: "https://pub.dev" + source: hosted + version: "1.16.0" + mustache_template: + dependency: transitive + description: + name: mustache_template + sha256: a46e26f91445bfb0b60519be280555b06792460b27b19e2b19ad5b9740df5d1c + url: "https://pub.dev" + source: hosted + version: "2.0.0" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + platform: + dependency: transitive + description: + name: platform + sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984" + url: "https://pub.dev" + source: hosted + version: "3.1.6" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + process: + dependency: transitive + description: + name: process + sha256: "107d8be718f120bbba9dcd1e95e3bd325b1b4a4f07db64154635ba03f2567a0d" + url: "https://pub.dev" + source: hosted + version: "5.0.3" + prompts: + dependency: transitive + description: + name: prompts + sha256: "3773b845e85a849f01e793c4fc18a45d52d7783b4cb6c0569fad19f9d0a774a1" + url: "https://pub.dev" + source: hosted + version: "2.0.0" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "7b3cfbf654f3edd0c6298ecd5be782ce997ddf0e00531b9464b55245185bbbbd" + url: "https://pub.dev" + source: hosted + version: "2.1.5" + pub_updater: + dependency: transitive + description: + name: pub_updater + sha256: "54e8dc865349059ebe7f163d6acce7c89eb958b8047e6d6e80ce93b13d7c9e60" + url: "https://pub.dev" + source: hosted + version: "0.4.0" + pubspec: + dependency: transitive + description: + name: pubspec + sha256: f534a50a2b4d48dc3bc0ec147c8bd7c304280fff23b153f3f11803c4d49d927e + url: "https://pub.dev" + source: hosted + version: "2.3.0" + quiver: + dependency: transitive + description: + name: quiver + sha256: ea0b925899e64ecdfbf9c7becb60d5b50e706ade44a85b2363be2a22d88117d2 + url: "https://pub.dev" + source: hosted + version: "3.2.2" + source_span: + dependency: transitive + description: + name: source_span + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" + source: hosted + version: "1.10.1" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" + url: "https://pub.dev" + source: hosted + version: "1.12.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "4ac0537115a24d772c408a2520ecd0abb99bca2ea9c4e634ccbdbfae64fe17ec" + url: "https://pub.dev" + source: hosted + version: "2.1.3" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + test_api: + dependency: transitive + description: + name: test_api + sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd + url: "https://pub.dev" + source: hosted + version: "0.7.4" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + uri: + dependency: transitive + description: + name: uri + sha256: "889eea21e953187c6099802b7b4cf5219ba8f3518f604a1033064d45b1b8268a" + url: "https://pub.dev" + source: hosted + version: "1.0.0" + web: + dependency: transitive + description: + name: web + sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb + url: "https://pub.dev" + source: hosted + version: "1.1.0" + yaml: + dependency: transitive + description: + name: yaml + sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce + url: "https://pub.dev" + source: hosted + version: "3.1.3" + yaml_edit: + dependency: transitive + description: + name: yaml_edit + sha256: fb38626579fb345ad00e674e2af3a5c9b0cc4b9bfb8fd7f7ff322c7c9e62aef5 + url: "https://pub.dev" + source: hosted + version: "2.2.2" +sdks: + dart: ">=3.5.0 <4.0.0" + flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index be315353..47c3330c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,62 +1,8 @@ name: flutter_background_service -description: A flutter plugin for executing dart code continously even application closed. -version: 0.2.6 -repository: https://github.com/ekasetiawans/flutter_background_service environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=2.0.0" + sdk: ">=2.17.5 <4.0.0" + flutter: ">=3.0.0" dependencies: - flutter: - sdk: flutter - -dev_dependencies: - flutter_test: - sdk: flutter - -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter. -flutter: - # This section identifies this Flutter project as a plugin project. - # The 'pluginClass' and Android 'package' identifiers should not ordinarily - # be modified. They are used by the tooling to maintain consistency when - # adding or updating assets for this project. - plugin: - platforms: - android: - package: id.flutter.flutter_background_service - pluginClass: FlutterBackgroundServicePlugin - ios: - pluginClass: FlutterBackgroundServicePlugin - # To add assets to your plugin package, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - # - # For details regarding assets in packages, see - # https://flutter.dev/assets-and-images/#from-packages - # - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware. - # To add custom fonts to your plugin package, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts in packages, see - # https://flutter.dev/custom-fonts/#from-packages + melos: ^6.1.0