Search in sources :

Example 1 with WorkRequest

use of androidx.work.WorkRequest in project Tusky by Vavassor.

the class NotificationHelper method enablePullNotifications.

public static void enablePullNotifications(Context context) {
    WorkManager workManager = WorkManager.getInstance(context);
    workManager.cancelAllWorkByTag(NOTIFICATION_PULL_TAG);
    WorkRequest workRequest = new PeriodicWorkRequest.Builder(NotificationWorker.class, PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS, TimeUnit.MILLISECONDS, PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS, TimeUnit.MILLISECONDS).addTag(NOTIFICATION_PULL_TAG).setConstraints(new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()).build();
    workManager.enqueue(workRequest);
    Log.d(TAG, "enabled notification checks with " + PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS + "ms interval");
}
Also used : WorkRequest(androidx.work.WorkRequest) PeriodicWorkRequest(androidx.work.PeriodicWorkRequest) WorkManager(androidx.work.WorkManager) TaskStackBuilder(androidx.core.app.TaskStackBuilder) PeriodicWorkRequest(androidx.work.PeriodicWorkRequest)

Example 2 with WorkRequest

use of androidx.work.WorkRequest in project fdroidclient by f-droid.

the class WifiStateChangeService method start.

public static void start(Context context, @Nullable Intent intent) {
    int networkInfoStateInt = NETWORK_INFO_STATE_NOT_SET;
    if (intent != null) {
        NetworkInfo ni = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        networkInfoStateInt = ni.getState().ordinal();
    }
    WorkRequest workRequest = new OneTimeWorkRequest.Builder(WifiStateChangeService.class).setConstraints(new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()).setInputData(new Data.Builder().putInt(WifiManager.EXTRA_NETWORK_INFO, networkInfoStateInt).build()).build();
    WorkManager.getInstance(context).enqueue(workRequest);
}
Also used : WorkRequest(androidx.work.WorkRequest) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest) Constraints(androidx.work.Constraints) NetworkInfo(android.net.NetworkInfo) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Aggregations

WorkRequest (androidx.work.WorkRequest)2 NetworkInfo (android.net.NetworkInfo)1 TaskStackBuilder (androidx.core.app.TaskStackBuilder)1 Constraints (androidx.work.Constraints)1 OneTimeWorkRequest (androidx.work.OneTimeWorkRequest)1 PeriodicWorkRequest (androidx.work.PeriodicWorkRequest)1 WorkManager (androidx.work.WorkManager)1