Android Oreo上的操作系统阻止了Geofence过渡PendingIntent

ste*_*neo 2 android google-play-services android-geofence google-location-services

这只发生在Android Oreo上.我正在使用Play Services 11.4.2.我正在使用GeofencingClient注册地理围栏,并将带有pendingIntent的addGeofences方法注册到处理地理围栏过渡的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
Run Code Online (Sandbox Code Playgroud)

一旦我在以下情况下添加地理围栏:

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

pin*_*ino 10

这是由新的Android Oreo后台服务限制引起的.

您必须将PendingIntent从使用服务更改为使用BroadcastReceiver.

有关更多信息和示例代码,请参阅此CodeLab.

  • 该示例是关于位置更新的,而不是关于地理要素的。此外,关于https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi的第一条评论是“此接口已弃用”。是否有适用于Android Oreo的GeofenceAPI的更好的代码示例? (2认同)