android - 同一地理围栏的多次注册

标签 android geofencing android-geofence

我想知道,Google 位置服务如何处理同一地理围栏的多次注册?

我了解到,在以下情况下,NEVER_EXPIRES 地理围栏会被删除:

  • 手机已重新启动
  • 网络位置已打开/关闭

并且仅在这种情况下列出。

所以,我正在考虑如何克服这种情况,当电话是前。无意中重启。我想出了在应用程序重新启动时注册地理围栏的方法。 但现在,我的问题是,如果在应用程序重新启动之间地理围栏尚未实际删除,会发生什么情况?他们会被取代吗? 例如,如果我注册完全相同的地理围栏 7x,关联的 Intent 会被触发 7x 还是仅触发一次?

感谢您的建议和指正!

最佳答案

不过,为时已晚,以防万一它对某人有帮助:

So, I am thinking about how to overcome this situations, when phone is for ex. unintentionally rebooted.

您应该使用广播接收器来监听: android.intent.action.BOOT_COMPLETED(处理重新启动)和 android.location.PROVIDERS_CHANGED(处理 loc 开/关)

I came up with registering geofences on application start all over again.

没有。如上所述,尝试在广播接收器中重新注册所有地理围栏。您可以启动一个服务,从上述广播接收器的 onReceive 中重新注册地理围栏。

But now, my question is, what will happen in case, that geofences haven't been actually removed between application re-starts? Will they be replaced? For example if I register the very same geofence 7x, will associated intent be fired 7x or just once?

无论您注册多少次地理围栏,只要使用相同的 requestId,都会被视为单个地理围栏。例如:

 mGeofenceList.add(new Geofence.Builder()
                // Set the request ID of the geofence. This is a string to identify this geofence.
                .setRequestId(requestId)
                .setCircularRegion(latPos, longPos, mRadius)
                .setExpirationDuration(Geofence.NEVER_EXPIRE)
                .setLoiteringDelay(LOITERING_DELAY)
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_DWELL)
                .build()); 

关于android - 同一地理围栏的多次注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23550057/

相关文章:

java - 应用程序崩溃而无法执行 AsyncTask

java - 即使convertView不为null,convertView.findViewById也会返回null

android - 如何在提供商更改时重新注册 android 地理围栏?

android - 如何使用 Android 地理围栏 API?

Android,当应用程序打开时显示 alertDialog 而不是通知

android - 如何在android中的Fragment中填写自定义列表?

Android - 在数据库中存储/设置 imageResource 路径?

ios - CLLocationManager 区域监控 : Detect Arrival in Suspended State

php - mysql中ST_Buffer的等价函数

android - 在 Android 中从地理围栏调用 Activity