Skip to main content

Geo-triggering

Start Geo-triggering

Geo-triggering allows the automatic detection of location context change events (such as entering or exiting a geofence, or crossing a Geoline™). For this capability, the SDK needs to be initialized and the app must have location permission. For many use cases, a foreground service notification is also recommended.

To start geo-triggering, you should create and start the GeoTriggeringService as below:

if (ServiceManager.getInstance(context).isBluedotServiceInitialized()) {
// The Bluedot SDK is initialized, you can start Geo-triggering.

GeoTriggeringService.builder()
.notification(notificationReference) // Notification to use to run Geo-triggering as a foreground service.
.notificationId(myNotificationId) // Optional id to use for foreground service notification. Use if your app will // run additional foreground services, or you wish to update the notification.
.start(myApplicationContext, // This context should be the Application context.
error -> {
if (error != null) {
// Something went wrong when starting Geo-triggering. Handle error here.
return;
}
// Geo-triggering has started successfully. Handle success here.
});
} else {
// The Bluedot SDK is not initialized. Initialize before starting Geo-triggering.
}

Receiving Geo-trigger events

Create a receiver in the Manifest to receive geo-trigger events (such as entering a location):

AndroidManifest
<application android:label="@string/app_name" >
    <receiver
       android:name="my.package.ExampleGeoTriggerReceiver"
       android:enabled="true"
       android:exported="false"
    >
       <intent-filter>
          <action android:name="io.bluedot.point.GEOTRIGGER" />
       </intent-filter>
    </receiver>
</application>
class ExampleGeoTriggerReceiver : GeoTriggeringEventReceiver() {
    override fun onZoneInfoUpdate(zones: List<ZoneInfo>, context: Context) {
       // Notification that the local cache of zones has been updated.
    }

    override fun onZoneEntryEvent(entryEvent: ZoneEntryEvent, context: Context) {
       // Notification that a zone has been entered/Geoline™ crossed.
    }

    override fun onZoneExitEvent(exitEvent: ZoneExitEvent, context: Context) {
       // Notification that an exit detection-enabled zone has been exited.
    }   
}

Stop Geo-triggering

If you only need geo-triggering for a limited period, once that period is over, you can stop the geo-trigger service.

GeoTriggeringService.stop(myContext, error -> { 
if (error != null) {
// Something went wrong stopping Geo-triggering. Handle error here.
return;
}

// Geo-triggering stopped successfully. Handle success here.
});

Geo-triggering start and stop status are provided through callbacks on the  geoTriggeringStatusListener, implemented as lambda functions in the above examples.