From 5d7947d0610881c7e0e9959d3da45932abb55ea1 Mon Sep 17 00:00:00 2001 From: Pooja Singh Date: Wed, 18 Oct 2023 16:25:36 +0530 Subject: [PATCH 01/11] add try catch block to stop crash --- .../flutter_background_service/WatchdogReceiver.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 index fa06fd9b..d279ec33 100644 --- 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 @@ -66,10 +66,14 @@ public void onReceive(Context context, Intent intent) { } if (!config.isManuallyStopped() && !isRunning) { - if (config.isForeground()) { - ContextCompat.startForegroundService(context, new Intent(context, BackgroundService.class)); - } else { - context.startService(new Intent(context, BackgroundService.class)); + 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(); } } } From 0276982a4fabc462ab5afda0369f3b49e98679e3 Mon Sep 17 00:00:00 2001 From: prkay <57384721+prkay@users.noreply.github.com> Date: Wed, 18 Oct 2023 17:57:37 +0530 Subject: [PATCH 02/11] path change --- packages/flutter_background_service/pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/flutter_background_service/pubspec.yaml b/packages/flutter_background_service/pubspec.yaml index 2efd58f0..f352a97d 100644 --- a/packages/flutter_background_service/pubspec.yaml +++ b/packages/flutter_background_service/pubspec.yaml @@ -15,7 +15,8 @@ dependencies: sdk: flutter flutter_background_service_platform_interface: ^5.0.0 - flutter_background_service_android: ^6.0.1 + flutter_background_service_android: + path: '../flutter_background_service_android' flutter_background_service_ios: ^5.0.0 dev_dependencies: flutter_test: From 0e19c20e73d98ae996ace2056ce74600b4158a8a Mon Sep 17 00:00:00 2001 From: prkay <57384721+prkay@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:09:49 +0530 Subject: [PATCH 03/11] pub update --- packages/flutter_background_service/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_background_service/pubspec.yaml b/packages/flutter_background_service/pubspec.yaml index f352a97d..e2c39943 100644 --- a/packages/flutter_background_service/pubspec.yaml +++ b/packages/flutter_background_service/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: flutter_background_service_platform_interface: ^5.0.0 flutter_background_service_android: - path: '../flutter_background_service_android' + path: ../flutter_background_service_android flutter_background_service_ios: ^5.0.0 dev_dependencies: flutter_test: From 67604af8344b00f4601f30cead4aaed00d304e61 Mon Sep 17 00:00:00 2001 From: prkay <57384721+prkay@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:20:53 +0530 Subject: [PATCH 04/11] Update pubspec.yaml --- packages/flutter_background_service/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_background_service/pubspec.yaml b/packages/flutter_background_service/pubspec.yaml index e2c39943..8561d967 100644 --- a/packages/flutter_background_service/pubspec.yaml +++ b/packages/flutter_background_service/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: flutter_background_service_platform_interface: ^5.0.0 flutter_background_service_android: - path: ../flutter_background_service_android + path: ./flutter_background_service_android flutter_background_service_ios: ^5.0.0 dev_dependencies: flutter_test: From 9647cc025774a66cd5115915d06dd54b91e4f491 Mon Sep 17 00:00:00 2001 From: prkay <57384721+prkay@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:35:23 +0530 Subject: [PATCH 05/11] Update pubspec.yaml --- packages/flutter_background_service/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_background_service/pubspec.yaml b/packages/flutter_background_service/pubspec.yaml index 8561d967..b02ed30e 100644 --- a/packages/flutter_background_service/pubspec.yaml +++ b/packages/flutter_background_service/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: flutter_background_service_platform_interface: ^5.0.0 flutter_background_service_android: - path: ./flutter_background_service_android + path: flutter_background_service_android flutter_background_service_ios: ^5.0.0 dev_dependencies: flutter_test: From a4873564c3ad8d157ae1af8aa9f260f1db62a969 Mon Sep 17 00:00:00 2001 From: prkay <57384721+prkay@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:38:32 +0530 Subject: [PATCH 06/11] Update pubspec.yaml --- packages/flutter_background_service/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_background_service/pubspec.yaml b/packages/flutter_background_service/pubspec.yaml index b02ed30e..e428a921 100644 --- a/packages/flutter_background_service/pubspec.yaml +++ b/packages/flutter_background_service/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: flutter_background_service_platform_interface: ^5.0.0 flutter_background_service_android: - path: flutter_background_service_android + path: packages/flutter_background_service_android flutter_background_service_ios: ^5.0.0 dev_dependencies: flutter_test: From 37200c0086ffd0284ffb18b033ef90e499536d28 Mon Sep 17 00:00:00 2001 From: prkay <57384721+prkay@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:44:38 +0530 Subject: [PATCH 07/11] Update pubspec.yaml --- packages/flutter_background_service/pubspec.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/flutter_background_service/pubspec.yaml b/packages/flutter_background_service/pubspec.yaml index e428a921..2c0b75a4 100644 --- a/packages/flutter_background_service/pubspec.yaml +++ b/packages/flutter_background_service/pubspec.yaml @@ -16,7 +16,10 @@ dependencies: flutter_background_service_platform_interface: ^5.0.0 flutter_background_service_android: - path: packages/flutter_background_service_android + git: + url: https://github.com/ekasetiawans/flutter_background_service.git + ref: a4873564c3ad8d157ae1af8aa9f260f1db62a969 + path: packages/flutter_background_service_android flutter_background_service_ios: ^5.0.0 dev_dependencies: flutter_test: From 78dc190d37001f64a2bb807bffba38fb9143b944 Mon Sep 17 00:00:00 2001 From: prkay <57384721+prkay@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:45:13 +0530 Subject: [PATCH 08/11] Update pubspec.yaml --- packages/flutter_background_service/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_background_service/pubspec.yaml b/packages/flutter_background_service/pubspec.yaml index 2c0b75a4..337d4118 100644 --- a/packages/flutter_background_service/pubspec.yaml +++ b/packages/flutter_background_service/pubspec.yaml @@ -18,7 +18,7 @@ dependencies: flutter_background_service_android: git: url: https://github.com/ekasetiawans/flutter_background_service.git - ref: a4873564c3ad8d157ae1af8aa9f260f1db62a969 + ref: 37200c0086ffd0284ffb18b033ef90e499536d28 path: packages/flutter_background_service_android flutter_background_service_ios: ^5.0.0 dev_dependencies: From 9a5732cef65ce5b33e699569cd88c98521c002ac Mon Sep 17 00:00:00 2001 From: Eka Setiawan Saputra Date: Thu, 19 Oct 2023 13:29:03 +0700 Subject: [PATCH 09/11] feat: throw an error if using FlutterBackgroundService class in worker isolate --- .../lib/flutter_background_service_android.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 index 7c8e8658..b6e37032 100644 --- a/packages/flutter_background_service_android/lib/flutter_background_service_android.dart +++ b/packages/flutter_background_service_android/lib/flutter_background_service_android.dart @@ -7,9 +7,13 @@ 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); @@ -29,7 +33,16 @@ class FlutterBackgroundServiceAndroid extends FlutterBackgroundServicePlatform { FlutterBackgroundServiceAndroid._(); static final FlutterBackgroundServiceAndroid _instance = FlutterBackgroundServiceAndroid._(); - factory FlutterBackgroundServiceAndroid() => _instance; + + 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); From dbb72c179b0a0ceb84f00aca35ce730b42a1973a Mon Sep 17 00:00:00 2001 From: Eka Setiawan Saputra Date: Thu, 19 Oct 2023 06:30:25 +0000 Subject: [PATCH 10/11] chore(release): publish packages - flutter_background_service_android@6.1.0 - flutter_background_service@5.0.2 --- CHANGELOG.md | 28 +++++++++++++++++++ .../flutter_background_service/CHANGELOG.md | 4 +++ .../example/pubspec.yaml | 2 +- .../flutter_background_service/pubspec.yaml | 8 ++---- .../CHANGELOG.md | 4 +++ .../pubspec.yaml | 2 +- 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58e77b3f..ac9f0a35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,34 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## 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 diff --git a/packages/flutter_background_service/CHANGELOG.md b/packages/flutter_background_service/CHANGELOG.md index 47ae2d11..80e810ff 100644 --- a/packages/flutter_background_service/CHANGELOG.md +++ b/packages/flutter_background_service/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.0.2 + + - Update a dependency to the latest release. + ## 5.0.1 - Update a dependency to the latest release. diff --git a/packages/flutter_background_service/example/pubspec.yaml b/packages/flutter_background_service/example/pubspec.yaml index 09536db0..f727eb90 100644 --- a/packages/flutter_background_service/example/pubspec.yaml +++ b/packages/flutter_background_service/example/pubspec.yaml @@ -39,7 +39,7 @@ dependencies: path: ../ flutter_background_service_ios: ^5.0.0 - flutter_background_service_android: ^6.0.1 + flutter_background_service_android: ^6.1.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.5 diff --git a/packages/flutter_background_service/pubspec.yaml b/packages/flutter_background_service/pubspec.yaml index 337d4118..0a69abe7 100644 --- a/packages/flutter_background_service/pubspec.yaml +++ b/packages/flutter_background_service/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_background_service description: A flutter plugin for executing dart code continously even application closed. -version: 5.0.1 +version: 5.0.2 repository: https://github.com/ekasetiawans/flutter_background_service funding: @@ -15,11 +15,7 @@ dependencies: sdk: flutter flutter_background_service_platform_interface: ^5.0.0 - flutter_background_service_android: - git: - url: https://github.com/ekasetiawans/flutter_background_service.git - ref: 37200c0086ffd0284ffb18b033ef90e499536d28 - path: packages/flutter_background_service_android + flutter_background_service_android: ^6.1.0 flutter_background_service_ios: ^5.0.0 dev_dependencies: flutter_test: diff --git a/packages/flutter_background_service_android/CHANGELOG.md b/packages/flutter_background_service_android/CHANGELOG.md index e6b5c478..ff56f986 100644 --- a/packages/flutter_background_service_android/CHANGELOG.md +++ b/packages/flutter_background_service_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 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)) diff --git a/packages/flutter_background_service_android/pubspec.yaml b/packages/flutter_background_service_android/pubspec.yaml index 1b53c3d1..144a693f 100644 --- a/packages/flutter_background_service_android/pubspec.yaml +++ b/packages/flutter_background_service_android/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_background_service_android description: A flutter plugin for executing dart code continously even application closed. -version: 6.0.1 +version: 6.1.0 repository: https://github.com/ekasetiawans/flutter_background_service environment: From 9ef2999d2dcc65755dde4e648d0539dbd92c5f72 Mon Sep 17 00:00:00 2001 From: Hugo Bedford <36144175+hbedford@users.noreply.github.com> Date: Fri, 13 Oct 2023 11:01:53 -0300 Subject: [PATCH 11/11] add function of open app --- .../BackgroundService.java | 20 +++++++++++++++++++ .../flutter_background_service_android.dart | 5 +++++ 2 files changed, 25 insertions(+) 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 index 0d9956bd..4c0fb0dc 100644 --- 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 @@ -317,6 +317,26 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result } 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(); 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 index b6e37032..11e47a92 100644 --- a/packages/flutter_background_service_android/lib/flutter_background_service_android.dart +++ b/packages/flutter_background_service_android/lib/flutter_background_service_android.dart @@ -222,4 +222,9 @@ class AndroidServiceInstance extends ServiceInstance { "value": value, }); } + + Future openApp() async { + final result = await _channel.invokeMethod('openApp'); + return result ?? false; + } }