Are Android geofences surviving a reboot?

不羁的心 提交于 2019-11-27 16:03:04

问题


is the system persisting them or do I have to add them again them after reboot? I have not found anything about that in the documentation at https://developer.android.com/training/location/geofencing.html


回答1:


Geofences will not persist on reboot. I have tested and you can find the sample here.

You have to listen for BOOT_COMPLETED action and add geofences again.

Note: If your app installed on external storage(SD card), you will never receive Boot Complete action. So you have to specify android:installLocation="internalOnly" in the manifest tag. This is because, android device will broadcast BOOT_COMPLETED action before setting up the external storage.




回答2:


I haven't found any documentation confirming this, but my own experiments have shown that they are not persisted across reboots.

My setup was as follows:

  • Run application
  • Application sets up various geofences on first launch only as NEVER_EXPIRE
  • Exit application
  • Use phone in regions marked by fences
  • Confirm fences trigger pending intents which are sent to IntentService
  • Leave region
  • Reboot phone
  • Re-enter region
  • Pending intent does not get sent to IntentService

If anyone has more information on this from someone at Google please comment!




回答3:


Which data do you want to persist? Is it the geofence region in your device or the geofence region stored by Google Play Service Location API ?

I believe the device need to register a region (defined by its latitude, longitude and radius) to Google Play Service (via LocationClient). You also need to provide expiration time, transition type you want to be notified, and the Intent from which you will be notified.

This region will be stored (remotely) not in your App. When it pass its expiration time, Google Play Service will automatically remove it. You can also set it as NEVER_EXPIRE. If the region is not expired yet, Google Play Service will notify your App (via intent that you send when calling addGeofences).

The source of the region (lat, long, radius) is up to your implementation.



来源:https://stackoverflow.com/questions/17040889/are-android-geofences-surviving-a-reboot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!