title: Android: BroadcastReceiver won't listen to BOOT_COMPLETED
body: <p>My app pushes a daily notification (this is working correctly) but after a device reboot notification won't fire again.</p>
  
  <p>I'm trying to set a BroadcastReceiver that listens to BOOT_COMPLETED to no avail.</p>
  
  <p>AndroidManifest.xml:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt;
  ...
  &lt;receiver android:name=".helpers.notification.AlarmRebootReceiver"
      android:enabled="false"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>BroadcastReceiver:</p>
  
  <pre><code>public class AlarmRebootReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context oContext, Intent intent) {
  
          try {    
              Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION");
              notificationIntent.addCategory("android.intent.category.DEFAULT");
  
              String notificationMessage = TMLocale.getStringResourceByName("reminder_newthought");
              String notificationTitle = TMLocale.getStringResourceByName("app_name");
  
              TMNotification.Notify(notificationTitle, notificationMessage, Enum.ArtAndWordsNotification.NEWTHOUGHT, oContext);
  
              TMNotification.cancelNewThoughtAlarm(oContext);
              scheduleNewThoughtAlarm(oContext);
          } catch (Exception e) {
              ExceptionHandler.logException(e);
          }
      }
  
      private void scheduleNewThoughtAlarm(Context oContext) {
  
          Calendar cal = Calendar.getInstance();
          int day = cal.get(Calendar.DAY_OF_MONTH);
          int month = cal.get(Calendar.MONTH);
          int year = cal.get(Calendar.YEAR);
          int hour = cal.get(Calendar.HOUR_OF_DAY);
          int minutes = cal.get(Calendar.MINUTE) + 1;
          int seconds = cal.get(Calendar.SECOND);
  
          Calendar newCalendar = TMDate.generateCalendar(day, month, year, hour, minutes, seconds);
          TMNotification.scheduleNewThoughtAlarm(oContext, newCalendar, null);
      }
  }
  </code></pre>
  
  <p>I set the boot receiver enabled to false in AndroidManifest and set it to true by code when alarm is created, as it suggest in official docs (this is so you listen to boot completed only when needed).</p>
  
  <p>Where notification is launched:</p>
  
  <pre><code>private static void doNewThoughtSchedule(Context oContext, int reminderPreference, boolean randomNotificationsPreference,
                                               Calendar calendar, Intent notificationIntent){
  
      ComponentName receiver = new ComponentName(ApplicationContext.get(), AlarmRebootReceiver.class);
      PackageManager pm = ApplicationContext.get().getPackageManager();
  
      pm.setComponentEnabledSetting(receiver,
              PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
              PackageManager.DONT_KILL_APP);
  
      ...
  }
  </code></pre>
  
  <p>Apparently everythings fine in code but rebooting the device won't push notification again.</p>
  
  <p>Tried in a Huawei Android 9 device as well as an older Android 4.4 phone. None worked.</p>
  
  <p>Any help?</p>
  
  <p>PS. TMNotification.scheduleNewThoughtAlarm method is irrelevant as it is working fine (setting a simple toast won't even show in onReceive).</p>
  
  <p>PS2. It's weird, but following exactly the official docs here doesn't wort either: <a href="https://developer.android.com/training/scheduling/alarms.html#java" rel="noreferrer">https://developer.android.com/training/scheduling/alarms.html#java</a> (where title is "Start an alarm when the device restarts").</p>