06 – Listen to geofence entries & exits

Implementation #

Please note! All the code snippets in this section have been provided for Android. If you use iOS, you’ll find it easy to translate them appropriately.

You may want to be aware of users entering and leaving the geofences of your building. In order to listen to these interactions you must implement GeofenceListener interface (Android). With this interface you will be notified with a list of Geofences when the user enters or leaves any of them:

private GeofenceListener geofenceListener = new GeofenceListener() {

    @Override
    public void onEnteredGeofences(List<Geofence> enteredGeofences) {
        Log.d(TAG, "onEnteredGeofences: ");
    }

    @Override
    public void onExitedGeofences(List<Geofence> exitedGeofences) {
        Log.d(TAG, "onExitedGeofences: ");
    }

};

In order to start using this listener you must attach it to our SDK with the following line of code:

// Make sure you have initialized our SDK with SitumSdk.init(Context)
SitumSdk.locationManager().setGeofenceListener(geofenceListener);

In case you want to stop this listener, do the following:

SitumSdk.locationManager().setGeofenceListener(null);

Remember to set this listener or not before the user starts positioning, it won’t work if you attach it while positioning.

Take in cosideration #

  • This listener will only work with SDK 2.80.0 onwards.
  • Positioning geofences (with trainer_metadata custom field) will be ignored by these callbacks. As this type of geofences are used to get better positioning in uncalibrated areas, the entries and exits inside them won’t be notified.
  • These callbacks only work with indoor locations. Any outdoor location will produce a call to onExitedGeofences with the last positioned geofences list as parameter.

Suscríbete a nuestro boletín

INFORMACIÓN BÁSICA SOBRE PROTECCIÓN DE DATOS

Responsable del tratamiento: SITUM TECHNOLOGIES, S.L.
Contacto: Responsable del tratamiento: situm@situm.es
Responsable de protección: dpo@situm.es
Finalidad y base legal: Gestionar el envío de newsletter de SITUM sólo con consentimiento.
Legitimación: Consentimiento expreso del interesado.
Destinatarios: Los datos no serán cedidos a terceros salvo obligación legal.
Plazo de conservación: Mientras la parte interesada permanezca suscrita al newsletter (en cada newsletter enviado por Situm estará disponible un link para darse de baja).
Derechos: El interesado podrá revocar en cualquier momento su consentimiento, así como ejercitar los derechos de oposición, acceso, conservación, rectificación, limitación, supresión de datos y no ser objeto de una decisión basada únicamente en el tratamiento automatizado de datos, dirigiéndose por escrito a SITUM en las direcciones indicadas.
Información Adicional: Puede consultar la información adicional y detallada sobre Protección de Datos en nuestra política de privacidad.

Por favor, descarga tu copia aquí.

Muchas gracias por descargar nuestro whitepaper. No dudes en contactar con nosotros si quieres saber más sobre cómo nuestras soluciones pueden ayudar a tu negocio.


Cerrar ventana