我有一个Android应用程序,它使用Awareness API在插入耳机时设置围栏.
我使用代码实现了AwarenessFence,就像以下示例中所示:https://developers.google.com/awareness/android-api/fence-register.
我有一个PendingIntent定义为:
PendingIntent.getBroadcast(context, 0, new Intent("my.application.packageFENCE_RECEIVER_ACTION"), 0)
Run Code Online (Sandbox Code Playgroud)
然后在我的AndroidManifest.xml文件中
<receiver android:name=".fence.FenceDetector$MyFenceReceiver">
<intent-filter>
<action android:name="my.application.packageFENCE_RECEIVER_ACTION" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
这是在Manifest中声明的,因为即使我的应用程序在后台,我也希望接收广播.
这在Android 7.0及更低版本上运行良好,但是当我在Android 8.0上运行时,我收到错误:
BroadcastQueue: Background execution not allowed: receiving Intent { act=my.application.packageFENCE_RECEIVER_ACTION
Run Code Online (Sandbox Code Playgroud)
我认为这是由于Android O上后台执行的新限制.
任何人都可以告诉我如何注册一个广播接收器,它可以在运行API 26的Android设备上在后台监听感知围栏触发器.
让我知道如果有些事情不清楚或者我需要详细说明.
提前致谢
android broadcastreceiver android-broadcastreceiver google-awareness android-8.0-oreo
android ×1