编程语言
首页 > 编程语言> > android – Geofence触发程序解释需要吗?

android – Geofence触发程序解释需要吗?

作者:互联网

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

    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,这次也没有触发地理围栏.基本上我想知道的是geonfences存储在哪里.如果它们存储在应用程序内存之外,那么为什么“删除代码段”会清除地理围栏?

解决方法:

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

希望这可以帮助.

标签:android-geofence,android,google-play-services,location-client
来源: https://codeday.me/bug/20190925/1816807.html