Skip to content

Handling Geofence Transitions Inside Your Application (Android)

Introduction

StreetHawk SDK can notify application when a user enter or exits a geofence created on StreetHawk dashboard so that application can further extend this event to implement the desired functionality.

Consider a use case in which you wish to send a promotion code to a user after he spends some time inside your shop to encourage him to buy the product. The use case can be simply achieved by

  1. Create a Geofence for you shop in StreetHawk console. Note this steps in independent of the code implementation and you can add or change geofences on the fly from you dashboard only

  2. Implement StreetHawkgeofence module's INotifyGeofenceTransition listener inside your application which notifies application when a user enters or exit a geofence

  3. Implement your logic for displaying promotion code

Code snippets

  • Add StreetHawk's Geofence module by following the steps document here.
  • Implement INotifyGeofenceTransition
public class AppService extends Service implements INotifyGeofenceTransition{
...

   @Override
    public void onDeviceEnteringGeofence() {

    /* Called when user enters a geofence */ 

    //Fetch list of geofences which the subject device entered
    ArrayList<GeofenceData> list = SHGeofence.getInstance(this).getGeofenceEnteredList();

    int delay = 10; // delay of 10 minutes
        String promitionCode = getPromotionCode();    // pseudo code for getting promotion code
        GenerateNotification(promitionCode.delay);  // pseudo code for displaying notification
    }

    @Override
    public void onDeviceLeavingGeofence() {
      /* Called when user leaves a geofence */

    //Fetch list of geofences which the subject device left
    ArrayList<GeofenceData> list = SHGeofence.getInstance(this).getGeofenceExitList();

    }
}