title: How to ensure PeriodicWorkRequests are called on device reboot on Android N and upwards
body: <p>I recently tried to use the <code>WorkManager</code>'s <code>PeriodicWorkRequest</code>s  as a surefire way of getting user location updates periodically in the background. The library met my requirements and this particular detail got my attention:</p>
  
  <blockquote>
    <p>Guarantees task execution, even if the app or device restarts</p>
  </blockquote>
  
  <p>Having implemented and tested it, I tried rebooting my device and noticed the Log message and App Notification never showed up.</p>
  
  <p>Naturally, I did some research and stumbled upon this: <a href="https://stackoverflow.com/questions/51439450/periodicworkrequest-not-working-after-device-reboot-in-android-oreo">PeriodicWorkRequest not working after device reboot in android oreo</a> </p>
  
  <p>So I tried using the <code>BOOT_COMPLETED</code> broadcast receiver to trigger the WorkRequest on device reboot but it didn't work. I checked numerous <code>BOOT_COMPLETED</code> receivers questions on SO but none worked, other than this here: <a href="https://stackoverflow.com/questions/41524459/broadcast-receiver-not-working-after-device-reboot-in-android">Broadcast Receiver Not Working After Device Reboot in Android</a> but that involved making the user select your app as an <a href="https://developer.android.com/reference/android/accessibilityservice/AccessibilityService" rel="nofollow noreferrer">AccessibilityService</a> which is a hinderance to the UX in my opinion.</p>
  
  <p>After some research I found out that the WorkManager uses the BOOT_COMPLETED BroadcastReceiver under the hood. I have been testing on Android Nougat and Oreo devices so far, so I tested the BroadcastReceiver on a Samsung running API 16, and also on an HTC running API 22. The Receiver worked and I removed them and also tested the WorkRequests on reboot; they worked too!</p>
  
  <p>Here's how I implemented my <code>PeriodicWorkRequest</code> </p>
  
  <pre><code>PeriodicWorkRequest request =
                  new PeriodicWorkRequest.Builder(LocationListenerWorker.class,
                          12, HOURS)
                          .build();
  
          mWorkManager.enqueueUniquePeriodicWork(Constants.LOCATION_TASK_ID,
                  ExistingPeriodicWorkPolicy.REPLACE, request);
  </code></pre>
  
  <p>Would appreciate any help on how to ensure the Requests also get called on device reboot on devices running API 24+ </p>