需要地理围栏触发程序解释吗?

Geofence triggering procedure explanation needed?

所以我创建了如下地理围栏:

    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);

我运行 这段代码一次,它在居住在地理围栏内时触发(如预期的那样)。然后我删除了片段并重新 运行 项目。但是即使我设置了NEVER_EXPIRE,这次地理围栏也没有触发。所以基本上我想知道的是地理围栏存储在哪里。如果它们存储在应用程序内存之外,那么为什么 "deleting snippet" 清除地理围栏?

我认为它正在按预期工作。重新 运行 的项目会将应用视为全新安装。如文档中所述 - 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.

希望对您有所帮助。