Location Triggered

Prerequisites

To use location triggered (Geofence) push, your app must request the following:

  • ACCESS_FINE_LOCATION
  • ACCESS_BACKGROUND_LOCATION if your app targets Android 10 (API level 29) or later.
info

Note

For location triggered push to work, ensure your Application has the following enabled: Location permission, Play Services location library, and device's location.

For more information, refer to Android Request Geofences.

SDK Installation

Installing using Catalog

Integration using a Version Catalog is the recommended way of integration; refer to the Configure Version Catalog document to configure a catalog if not done already. Once you have configured the catalog add the dependency in the app/build.gradle file, as shown below

build.gradle
dependencies {
     ...
    implementation(moengage.geofence)
}

Alternatively, you can add the dependency using Artifact ID as described in Installation using Artifact ID. However, installation using Catalog ID is the recommended approach as installing using Artifact ID may lead to version mismatch if mapped incorrectly. 

Configure Geofence

By default, the geofence feature is not enabled. To enable the feature, call the below API.

Kotlin Java
MoEGeofenceHelper.getInstance().startGeofenceMonitoring(context)

At any time if you want to stop the geofence monitoring or feature, use the below API. This API will remove the existing geofences.

Kotlin Java
MoEGeofenceHelper.getInstance().stopGeofenceMonitoring(context)

Callback

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, the application can just use the callback for logging/analytical purposes and let MoEngage process the trigger.

For more information about implementing callback in the application using OnGeofenceHitListener

Register the listener in the Application class onCreate() using MoEGeofenceHelper.getInstance().addListener().

Previous

Next

Was this article helpful?
0 out of 1 found this helpful

How can we improve this article?