Awareness API & Android O using BroadcastReceiver : <p>I have an Android app which uses the Awareness API to setup a fence when a headset is plugged in. </p>

<p>I have implemented the AwarenessFence using code much like in the examples at: <a href="https://developers.google.com/awareness/android-api/fence-register" rel="noreferrer">https://developers.google.com/awareness/android-api/fence-register</a>.</p>

<p>I have a PendingIntent defined as: </p>

<pre><code>PendingIntent.getBroadcast(context, 0, new Intent("my.application.packageFENCE_RECEIVER_ACTION"), 0)
</code></pre>

<p>Then in my AndroidManifest.xml file I have</p>

<pre><code>&lt;receiver android:name=".fence.FenceDetector$MyFenceReceiver"&gt;
&lt;intent-filter&gt;
    &lt;action android:name="my.application.packageFENCE_RECEIVER_ACTION" /&gt;
&lt;/intent-filter&gt;
</code></pre>

<p></p>

<p>This is declared in the Manifest due to the fact that I want to receive broadcasts even when my app is in the background.</p>

<p>This all worked fine on Android 7.0 and below, but when I run this on a Android 8.0 I get the error:</p>

<pre><code>BroadcastQueue: Background execution not allowed: receiving Intent { act=my.application.packageFENCE_RECEIVER_ACTION
</code></pre>

<p>I assume this is due to the new restrictions for background execution on Android O.</p>

<p>Can anybody tell me how to register a broadcast receiver which can listen to awareness fence triggers when in the background on a Android device running API 26.</p>

<p>Let me know If there is something which is unclear or if I need to elaborate something.</p>

<p>Thanks in advance</p>
