diff --git a/app/src/main/java/eu/faircode/email/WorkerFolderSync.java b/app/src/main/java/eu/faircode/email/WorkerFolderSync.java index 2da2297824..4421975ab1 100644 --- a/app/src/main/java/eu/faircode/email/WorkerFolderSync.java +++ b/app/src/main/java/eu/faircode/email/WorkerFolderSync.java @@ -12,7 +12,9 @@ import javax.mail.Session; import javax.mail.Store; import androidx.annotation.NonNull; +import androidx.work.Constraints; import androidx.work.Data; +import androidx.work.NetworkType; import androidx.work.OneTimeWorkRequest; import androidx.work.WorkInfo; import androidx.work.WorkManager; @@ -98,10 +100,14 @@ public class WorkerFolderSync extends Worker { Log.w(ex); } + Constraints.Builder constraints = new Constraints.Builder(); + constraints.setRequiredNetworkType(NetworkType.CONNECTED); + Data data = new Data.Builder().putLong("account", aid).build(); OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(WorkerFolderSync.class) .addTag(tag) + .setConstraints(constraints.build()) .setInputData(data) .build(); WorkManager.getInstance().enqueue(workRequest); diff --git a/app/src/main/java/eu/faircode/email/WorkerOperations.java b/app/src/main/java/eu/faircode/email/WorkerOperations.java index d8cee65919..af47ff3849 100644 --- a/app/src/main/java/eu/faircode/email/WorkerOperations.java +++ b/app/src/main/java/eu/faircode/email/WorkerOperations.java @@ -15,7 +15,9 @@ import javax.mail.event.StoreEvent; import javax.mail.event.StoreListener; import androidx.annotation.NonNull; +import androidx.work.Constraints; import androidx.work.Data; +import androidx.work.NetworkType; import androidx.work.OneTimeWorkRequest; import androidx.work.WorkInfo; import androidx.work.WorkManager; @@ -132,10 +134,14 @@ public class WorkerOperations extends Worker { Log.w(ex); } + Constraints.Builder constraints = new Constraints.Builder(); + constraints.setRequiredNetworkType(NetworkType.CONNECTED); + Data data = new Data.Builder().putLong("folder", fid).build(); OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(WorkerOperations.class) .addTag(tag) + .setConstraints(constraints.build()) .setInputData(data) .build(); WorkManager.getInstance().enqueue(workRequest);