Android Features – Fence triggering

Point SDK supports the triggering of actions by entering a pre-defined geographical area (Geofence) or crossing a GEOLINE™. When a Geofence or GEOLINE™ is triggered, a check-in notification is sent to Point Access and the Actions pertaining to the Zone containing the Geofence or GEOLINE™ are executed; the Zone is then disabled for the duration of its configurable Minimum Retrigger Time (MRT).

Custom actions

If a Zone contains a Custom Action, then the onCheckIntoFence method within an implementation of ApplicationNotificationListener is called.

It is best practice to register the ApplicationNotificationListener callback in onBlueDotPointServiceStartedSuccess and remove it in onBlueDotPointServiceStop. While in an Activity, it is recommended to add the ApplicationNotificationListener in onResume and unregister it in onPause.

image

Thread safety

These callbacks should be thread-safe and should not update UI views directly. If a UI view needs to be updated from within the callback it must be wrapped into runOnUiThread or a Handler.

Examples

This is an example of how to use App Notifications in an Application. Alternatively, for integration within an Activity, Service or Fragment, examples are available here.

public class BDTestApplication extends Application implements ServiceStatusListener,ApplicationNotificationListener {
    private Handler handler;
    ...
 
    @Override
    public void onCreate() {
        super.onCreate();
 
        // Initializing Handler bound to UI Thread
        handler = new Handler(Looper.getMainLooper());
        ...
    }
 
    @Override
    public void onBlueDotPointServiceStartedSuccess() {
        mServiceManager.subscribeForApplicationNotification(this);
    }
    ...
    @Override
    public void onCheckIntoFence(FenceInfo fenceInfo, ZoneInfo zoneInfo, LocationInfo location, Map<String, String> customData, boolean isCheckOut) {
        // This method will be called if the device checked into a Fence
        // and the zone contains a custom action
        // Using a handler to pass Runnable into UI thread to interact with UI elements
        handler.post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getApplicationContext(),"Checked into fence: " + fenceInfo.getName(),Toast.LENGTH_LONG).show();
            }
        });
    }
    ...
     
    @Override
    public void onBlueDotPointServiceStop() {
        mServiceManager.unsubscribeForApplicationNotification(this);
    }
    ...
}

The following is an example of how to use App Notifications in an Activity:

public class TestActivity extends Activity implements ApplicationNotificationListener {
     
    @Override
    protected void onResume() {
        super.onResume();
        mServiceManager.subscribeForApplicationNotification(this);
    }
    ...
     
    @Override
    public void onCheckIntoFence(FenceInfo fenceInfo, ZoneInfo zoneInfo, LocationInfo location, Map<String, String> customData, boolean isCheckOut) {
        // This method will be called if the device checked into a Fence
        // and the zone contains a custom action
        // Using runOnUiThread to interact with UI Elements within UI Thread
        final String fenceName = fenceInfo.getName();
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getApplicationContext(), "Entered: " + fenceName, Toast.LENGTH_LONG).show();
            }
        });
    }
    ...
     
    @Override
    protected void onPause() {
        super.onPause();
        mServiceManager.unsubscribeForApplicationNotification(this);
    }
}

This method passes back:

  • The name, description and geometry of the triggered Geofence or Geoline™.
  • Which zone the fence belongs to, including:
    • the name and description of the zone
    • the id of the zone
    • a reference to all the fence and beacon information within that zone
  • The geographical location at which the trigger occurred.
  • The custom fields configured for the custom action in Point Access web interface, refer to Point Access – Setting custom data fields for how to create and edit custom data fields in Point Access web interface.
  • Whether the fence will trigger the following checkout.

If the isCheckOut flag is set to true, when the device leaves the checked-in area then a subsequent check-out callback will also be made:

@Override
public void onCheckedOutFromFence(FenceInfo fenceInfo, ZoneInfo zoneInfo, int dwellTime, Map<String, String> customData) {
    // This method will be called when a device leaves the Fence that was checked into. Only applies to zones flagged as checkout enabled on the backend.
}
...

The documentation section on the check-out feature discusses this behavior in detail.

Created by Bluedot DevOps on June 19, 2018

Start the discussion