Android – 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 GeoTriggeringService as below:

GeoTriggeringService.builder()
    .notificationId(myNotificationId) // If running a foreground service
     .notification(notificationReference) // As above
     .start(myApplicationContext, // This context should be the Application context
        (error) -> { error != null?Log.d("bluedot", "Error in starting Bluedot geo-triggering: "+error.getMessage():return; })

Receiving Geo-trigger events

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

<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 -> {error != null? Log.d("bluedot","Error in stopping GeoTriggerService"+error.getReason()):return;})

Here GeoTriggeringService stop status will be provided through geoTriggeringStatusListener.

Created by Melwin Chiramel on December 21, 2020