diff --git a/android/app/src/main/AndroidManifestBase.xml b/android/app/src/main/AndroidManifestBase.xml
index b03c8a925..3c122b0bc 100644
--- a/android/app/src/main/AndroidManifestBase.xml
+++ b/android/app/src/main/AndroidManifestBase.xml
@@ -102,6 +102,10 @@
+
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,
+ ),
+ );
+}
+
class BackgroundTasks {
void registerSyncTask({bool changeExisting = false}) async {
try {
@@ -206,39 +225,54 @@ class BackgroundTasks {
return;
}
- await Workmanager().initialize(
- callbackDispatcher,
- isInDebugMode: true,
- );
+ // await service.configure(
+ // androidConfiguration: AndroidConfiguration(
+ // // this will be executed when app is in foreground or background in separated isolate
+ // onStart: onStart,
- final inputData = {"sync_all": syncAll};
- final constraints = Constraints(
- networkType:
- syncMode.type == SyncType.unobtrusive ? NetworkType.unmetered : NetworkType.connected,
- requiresBatteryNotLow: syncMode.type == SyncType.unobtrusive,
- requiresCharging: syncMode.type == SyncType.unobtrusive,
- requiresDeviceIdle: syncMode.type == SyncType.unobtrusive,
- );
+ // // auto start service
+ // autoStart: true,
+ // isForegroundMode: true,
- if (Platform.isIOS && syncMode.type == SyncType.unobtrusive) {
- // await Workmanager().registerOneOffTask(
- // moneroSyncTaskKey,
- // moneroSyncTaskKey,
- // initialDelay: syncMode.frequency,
- // existingWorkPolicy: ExistingWorkPolicy.replace,
- // inputData: inputData,
- // constraints: constraints,
- // );
- await Workmanager().registerOneOffTask(
- mwebSyncTaskKey,
- mwebSyncTaskKey,
- initialDelay: Duration(seconds: 30),
- existingWorkPolicy: ExistingWorkPolicy.replace,
- inputData: inputData,
- constraints: constraints,
- );
- return;
- }
+ // notificationChannelId: notificationChannelId, // this must match with notification channel you created above.
+ // initialNotificationTitle: 'AWESOME SERVICE',
+ // initialNotificationContent: 'Initializing',
+ // foregroundServiceNotificationId: notificationId,
+ // );
+
+ // await Workmanager().initialize(
+ // callbackDispatcher,
+ // isInDebugMode: true,
+ // );
+
+ // final inputData = {"sync_all": syncAll};
+ // final constraints = Constraints(
+ // networkType:
+ // syncMode.type == SyncType.unobtrusive ? NetworkType.unmetered : NetworkType.connected,
+ // requiresBatteryNotLow: syncMode.type == SyncType.unobtrusive,
+ // requiresCharging: syncMode.type == SyncType.unobtrusive,
+ // requiresDeviceIdle: syncMode.type == SyncType.unobtrusive,
+ // );
+
+ // if (Platform.isIOS && syncMode.type == SyncType.unobtrusive) {
+ // // await Workmanager().registerOneOffTask(
+ // // moneroSyncTaskKey,
+ // // moneroSyncTaskKey,
+ // // initialDelay: syncMode.frequency,
+ // // existingWorkPolicy: ExistingWorkPolicy.replace,
+ // // inputData: inputData,
+ // // constraints: constraints,
+ // // );
+ // await Workmanager().registerOneOffTask(
+ // mwebSyncTaskKey,
+ // mwebSyncTaskKey,
+ // initialDelay: Duration(seconds: 30),
+ // existingWorkPolicy: ExistingWorkPolicy.replace,
+ // inputData: inputData,
+ // constraints: constraints,
+ // );
+ // return;
+ // }
// await Workmanager().registerPeriodicTask(
// moneroSyncTaskKey,
@@ -249,15 +283,15 @@ class BackgroundTasks {
// inputData: inputData,
// constraints: constraints,
// );
- await Workmanager().registerPeriodicTask(
- mwebSyncTaskKey,
- mwebSyncTaskKey,
- initialDelay: syncMode.frequency,
- frequency: syncMode.frequency,
- existingWorkPolicy: changeExisting ? ExistingWorkPolicy.replace : ExistingWorkPolicy.keep,
- inputData: inputData,
- constraints: constraints,
- );
+ // await Workmanager().registerPeriodicTask(
+ // mwebSyncTaskKey,
+ // mwebSyncTaskKey,
+ // initialDelay: syncMode.frequency,
+ // frequency: syncMode.frequency,
+ // existingWorkPolicy: changeExisting ? ExistingWorkPolicy.replace : ExistingWorkPolicy.keep,
+ // inputData: inputData,
+ // constraints: constraints,
+ // );
} catch (error, stackTrace) {
print(error);
print(stackTrace);
diff --git a/pubspec_base.yaml b/pubspec_base.yaml
index 6e07b989b..2bf30723e 100644
--- a/pubspec_base.yaml
+++ b/pubspec_base.yaml
@@ -65,6 +65,7 @@ dependencies:
url: https://github.com/cake-tech/device_display_brightness.git
ref: master
workmanager: ^0.5.1
+ flutter_background_service: ^5.0.9
wakelock_plus: ^1.2.5
flutter_mailer: ^2.0.2
device_info_plus: ^9.1.0