Android Oreo上的操作系统阻止Geofence过渡挂起内容

Android Oreo上的操作系统阻止Geofence过渡挂起内容,android,google-play-services,android-geofence,google-location-services,Android,Google Play Services,Android Geofence,Google Location Services,这只发生在Android Oreo上。我正在使用Play Services 11.4.2。 我正在使用GeofencingClient和addGeofences方法注册geofences,并将PendingEvent添加到处理geofence转换的IntentService。 在某些情况下,操作系统会阻止播放服务发送的意图 系统将记录以下内容: Background start not allowed: service Intent { cmp=my.app.id/my.package.stru

这只发生在Android Oreo上。我正在使用Play Services 11.4.2。 我正在使用GeofencingClient和addGeofences方法注册geofences,并将PendingEvent添加到处理geofence转换的IntentService。 在某些情况下,操作系统会阻止播放服务发送的意图

系统将记录以下内容:

Background start not allowed: service Intent { cmp=my.app.id/my.package.struct.GeofenceTransIntentService (has extras) } to my.app.id/my.package.struct.GeofenceTransIntentService from pid=-1 uid=10154 pkg=my.app.id
一旦我在以下情况下添加了土工围栏:

  • 当我在设备启动后添加它时
  • 当我在应用程序被刷卡后添加它时 在这两种情况下,应用程序实际上已经在后台运行了(因为我能够运行添加geofence的代码),因为我听的是提供者改变了,引导完成了
    • 这是由新的

      您必须将挂起内容从使用服务更改为使用广播接收器


      有关更多信息和示例代码,请参阅此部分。

      除了在已接受的回答中提到的切换到BroadcastReceiver外,我还想指出,尽管您仍将收到BOOT_COMPLETED,但您将无法再接收已更改的提供程序

      是隐式广播,不在列表中

      在广播例外列表中,这就是为什么您仍然会收到它


      如果您想了解切换位置服务时获取挂钩的另一种方法,请参阅以了解更多详细信息。

      您能告诉我们您正在使用的代码吗?我刚切换到广播接收器,它工作了!非常感谢。这个例子是关于位置更新的,而不是关于geofeces。此外,第一条评论是“此接口已弃用”。是否有更好的适用于Android Oreo的GeofenceAPI代码示例?有关如何在Android Oreo及更高版本上处理此问题的更多详细信息,请参阅。