use of androidx.work.OneTimeWorkRequest in project AntennaPod by AntennaPod.
the class SyncService method syncImmediately.
public static void syncImmediately(Context context) {
OneTimeWorkRequest workRequest = getWorkRequest().setInitialDelay(0L, TimeUnit.SECONDS).build();
WorkManager.getInstance(context).enqueueUniqueWork(WORK_ID_SYNC, ExistingWorkPolicy.REPLACE, workRequest);
}
use of androidx.work.OneTimeWorkRequest in project AntennaPod by AntennaPod.
the class SyncService method fullSync.
public static void fullSync(Context context) {
LockingAsyncExecutor.executeLockedAsync(() -> {
SynchronizationSettings.resetTimestamps();
OneTimeWorkRequest workRequest = getWorkRequest().setInitialDelay(0L, TimeUnit.SECONDS).build();
WorkManager.getInstance(context).enqueueUniqueWork(WORK_ID_SYNC, ExistingWorkPolicy.REPLACE, workRequest);
});
}
use of androidx.work.OneTimeWorkRequest in project AntennaPod by AntennaPod.
the class AutoUpdateManager method restartUpdateTimeOfDayAlarm.
/**
* Sets time of day the feeds are refreshed automatically
*/
private static void restartUpdateTimeOfDayAlarm(int hoursOfDay, int minute, Context context) {
Log.d(TAG, "Restarting update alarm.");
Calendar now = Calendar.getInstance();
Calendar alarm = (Calendar) now.clone();
alarm.set(Calendar.HOUR_OF_DAY, hoursOfDay);
alarm.set(Calendar.MINUTE, minute);
if (alarm.before(now) || alarm.equals(now)) {
alarm.add(Calendar.DATE, 1);
}
long triggerAtMillis = alarm.getTimeInMillis() - now.getTimeInMillis();
OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(FeedUpdateWorker.class).setConstraints(getConstraints()).setInitialDelay(triggerAtMillis, TimeUnit.MILLISECONDS).build();
WorkManager.getInstance(context).enqueueUniqueWork(WORK_ID_FEED_UPDATE, ExistingWorkPolicy.REPLACE, workRequest);
}
use of androidx.work.OneTimeWorkRequest in project quickstart-android by firebase.
the class MyFirebaseMessagingService method scheduleJob.
// [END on_new_token]
/**
* Schedule async work using WorkManager.
*/
private void scheduleJob() {
// [START dispatch_job]
OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(MyWorker.class).build();
WorkManager.getInstance(this).beginWith(work).enqueue();
// [END dispatch_job]
}
use of androidx.work.OneTimeWorkRequest in project android-job by evernote.
the class JobProxyWorkManager method plantOneOff.
@Override
public void plantOneOff(JobRequest request) {
if (request.isTransient()) {
TransientBundleHolder.putBundle(request.getJobId(), request.getTransientExtras());
}
OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(PlatformWorker.class).setInitialDelay(request.getStartMs(), // don't use the average here, WorkManager will do the right thing
TimeUnit.MILLISECONDS).setConstraints(buildConstraints(request)).addTag(createTag(request.getJobId())).build();
// don't set the back-off criteria, android-job is handling this
WorkManager workManager = getWorkManager();
if (workManager == null) {
throw new JobProxyIllegalStateException("WorkManager is null");
}
workManager.enqueue(workRequest);
}
Aggregations