Geofence triggering procedure explanation needed?

2019-01-09 19:35发布

问题:

SO I've created geofence as below:

    GeofenceModel modelExit = new GeofenceModel.Builder("id_oi_456")
                .setTransition(Geofence.GEOFENCE_TRANSITION_DWELL)
                .setExpiration(Geofence.NEVER_EXPIRE)
                .setLatitude(40.414341)
                .setLongitude(49.928548)
                .setRadius(CLIENT_GEOFENCE_RADIUS)
                .build();


    SmartLocation.with(this).geofencing()
                .add(modelExit)
                .start(this);

I run this code once, it triggers when dwelling inside geofence (as expected). And then I delete the snippet and rerun the project. But geofence not triggered this time even if I have set NEVER_EXPIRE. So basically what I want to know is that where are the geonfences stored. In case they are stored outside app memory then why "deleting snippet" clears geofence?

回答1:

I think it is working as intended. The project that goes to re-run will consider the app as fresh install. As stated in the documentation - Use Best Practices for Geofencing:

The app must re-register geofences if they're still needed after the following events, since the system cannot recover the geofences in the following cases:

  • The device is rebooted. The app should listen for the device's boot complete action, and then re- register the geofences required.
  • The app is uninstalled and re-installed.
  • The app's data is cleared.
  • Google Play services data is cleared.
  • The app has received a GEOFENCE_NOT_AVAILABLE alert. This typically happens after NLP (Android's Network Location Provider) is disabled.

Hope this helps.