title: Run worker every time internet is available
body: <p>I am developing an Android app, and I used the Firebase JobDispatcher library to run a background job every time the user turns on Wi-Fi or mobile data, but unfortunately the library was deprecated and now the new WorkerManager is the way to go.</p>
  
  <p>My question is how to run a job using the WorkerManager every time the internet is available <strong>only</strong>?</p>
  
  <p>I have checked the WorkerManager library migration guide and documentation, but I couldn't achieve that using OneTimeWorkRequest or PeriodicWorkRequest.</p>
  
  <p>Here is the code I used with the Firebase JobDispatcher library to achieve that.</p>
  
  <pre><code>FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
  
  Job networkJob = dispatcher.newJobBuilder()
          .setService(NetworkJobService.class)
          .setTag(Const.NETWORK_JOB_TAG)
          .setReplaceCurrent(true)
          .setLifetime(Lifetime.FOREVER)
          .setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
          .setRecurring(true)
          .setTrigger(Trigger.executionWindow(0, 0))
          .setConstraints(Constraint.ON_ANY_NETWORK)
          .build();
  
      dispatcher.schedule(networkJob);
  </code></pre>