Geo Fence Push
Before configuring Geofences please make sure General Push Configuration is completed.
By default SDK does not track location neither geo-fence campaigns work by default.
To track location and run geo-fence campaigns you need to opt-in for location service in the MoEngage initialiser.
To initialise call the below opt-in API.
val moEngage = MoEngage.Builder(this, "XXXXXXXX")
.enableLocationServices()//enabled To track location and run geo-fence
.build()
MoEngage.initialise(moEngage)
MoEngage moEngage = new MoEngage.Builder(this, "XXXXXXXXXXX")
.enableLocationServices()
.build();
MoEngage.initialise(moEngage);
Note
For Geo-fence pushes to work your Application should have location permission and Play Services' Location Library should be included.
Geofence hit callbacks
MoEngage SDK optionally notifies the application whenever a Geo-Fence is triggered. If required the application can consume the trigger and ask the SDK not to process it, alternatively application can just use the callback for logging/analytical purposes and let MoEngage process the trigger.
To get the callback application needs to implement OnGeofenceHitListener API Reference and register this listener in the Application class's onCreate().
Implement OnGeofenceHitListener interface
class GeoFenceHitListener : OnGeofenceHitListener{
override fun geofenceHit(geoFenceHit: Intent?): Boolean {
// process the intent.
// return true if the app does not want the SDK to process the Geo-fence callback else false
return false
}
}
public class GeoFenceHitListener implements OnGeofenceHitListener {
@Override public boolean geofenceHit(Intent geoFenceHit) {
// process the intent.
// return true if the app does not want the SDK to process the Geo-fence callback else false
return false;
}
}
Register the listener
MoEGeofenceHelper.getInstance().registerGeofenceHitListener(GeoFenceHitListener())
MoEGeofenceHelper.getInstance().registerGeofenceHitListener(new GeoFenceHitListener());
Updated over 6 years ago
