title: Background execution not allowed receiving intent BOOT_COMPLETED
body: <p>I've read about Android Oreo background execution limitations, and it clearly states that <code>BOOT_COMPLETED</code> broadcast is unaffected, but I can't get it to work on Android Oreo.</p>
  
  <p>First, I am compiling against SDK 27. Secondly, I declared the receiver inside the manifest file:</p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt;
      &lt;receiver
          android:name="helpers.StartDetectionAtBoot"
          android:label="StartDetectionAtBoot"
          android:enabled="true"
          android:exported="true"&gt;
          &lt;intent-filter&gt;
              &lt;category android:name="android.intent.category.DEFAULT"/&gt;
  
              &lt;action android:name="android.intent.action.MY_PACKAGE_REPLACED"/&gt;
  
              &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt;
              &lt;action android:name="android.intent.action.QUICKBOOT_POWERON"/&gt;
              &lt;!--For HTC devices--&gt;
              &lt;action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/&gt;
              &lt;!--For MIUI devices--&gt;
              &lt;action android:name="android.intent.action.REBOOT"/&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p>Then there's the implementation of the receiver, which can also be simple as that:</p>
  
  <pre><code>public class StartDetectionAtBoot extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Log.i("test", "test");
  
          Intent intent0 = new Intent( context, ActivityRecognitionService.class );
          PendingIntent pendingIntent = PendingIntent.getService(context, 111, intent0, PendingIntent.FLAG_UPDATE_CURRENT);
          ActivityRecognitionClient activityRecognitionClient = ActivityRecognition.getClient(context);
          activityRecognitionClient.requestActivityUpdates(5000, pendingIntent);
      }
  }
  </code></pre>
  
  <p><code>onReceive</code> method is not called and I will always get logcat error on Android Oreo devices/emulator:</p>
  
  <blockquote>
    <p>W/BroadcastQueue: Background execution not allowed: receiving Intent {
    act=android.intent.action.BOOT_COMPLETED flg=0x400010 }</p>
  </blockquote>
  
  <p>Reading other answers, they said there were some problems when registering explicit intents in the manifest but this is not the case of <code>BOOT_COMPLETED</code> one.</p>
  
  <p>Neither <a href="https://stackoverflow.com/questions/46431606/background-execution-not-allowed-android-o-pendingintent">this</a> helped because the receiver is not called at all.</p>
  
  <p>Registering broadcast intent at runtime, get it to work (on the emulator, firing the intent from adb shell), but I'm not sure it's the right way to do it:</p>
  
  <pre><code>registerReceiver(new StartDetectionAtBoot(), new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
  </code></pre>
  
  <p>Are there any known bugs with this?</p>