Geofence在Android Oreo上切换操作系统阻止的PendingIntent [英] Geofence transition PendingIntent blocked by the OS on Android Oreo

查看:352
本文介绍了Geofence在Android Oreo上切换操作系统阻止的PendingIntent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



系统记录以下内容:

 不允许后台启动:service Intent {cmp = my.app.id / my.package.struct.GeofenceTransIntentService(有额外功能)} my.app .id / my.package.struct.GeofenceTransIntentService from pid = -1 uid = 10154 pkg = my.app.id 

只要在以下情况下添加地理围栏:在设备启动后添加它时,



  • 在应用程序被刷完后添加它
    在两种情况下,应用程序实际上已经在后台运行(因为我可以运行添加geofence的代码),因为我听到PROVIDERS_CHANGED,BOOT_COMPLETED。


解决方案

这是由新的安德oid Oreo后台服务限制

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



请参阅 CodeLab 获取更多信息和示例代码。


This only happens on Android Oreo. I'm using Play Services 11.4.2. I'm registering geofences using the GeofencingClient and the addGeofences method with a pendingIntent to an IntentService that is handling geofence transitions. It looks like the intent sent by the play services is blocked by the OS in certain conditions.

The system logs the following:

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

as soon as I add a geofence in the following situations:

  • when I add it after the device boots
  • when I add it after the app was swiped In both occasions the app is actually already running in the background (since I'm able to run the code that adds the geofence) because I listen to the PROVIDERS_CHANGED, BOOT_COMPLETED.

解决方案

This is caused by the new Android Oreo background service limitations.

You have to change the PendingIntent from using a Service to using a BroadcastReceiver.

See this CodeLab for further information and example code.

这篇关于Geofence在Android Oreo上切换操作系统阻止的PendingIntent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆