Android Oreo 上的操作系统阻止了地理围栏转换 PendingIntent

2024-04-28

这只发生在 Android Oreo 上。我正在使用 Play 服务 11.4.2。 我正在使用 GeofencingClient 和 addGeofences 方法将地理围栏注册到正在处理地理围栏转换的 IntentService 中,并将悬而未决的Intent 方法。 看起来播放服务发送的意图在某些情况下被操作系统阻止。

系统记录以下内容:

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

在以下情况下添加地理围栏后:

  • 当我在设备启动后添加它时
  • 当我在应用程序刷卡后添加它时 在这两种情况下,应用程序实际上已经在后台运行(因为我能够运行添加地理围栏的代码),因为我监听了 PROVIDERS_CHANGED、BOOT_COMPLETED。

这是新版造成的Android Oreo 后台服务限制 https://developer.android.com/about/versions/oreo/background.html#services.

您必须更改 PendingIntent 使用Service使用一个广播接收器.

看到这个CodeLab https://codelabs.developers.google.com/codelabs/background-location-updates-android-o/#0获取更多信息和示例代码。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Oreo 上的操作系统阻止了地理围栏转换 PendingIntent 的相关文章

随机推荐