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.
 

NOTE

For location triggered push to work, ensure your Application has:

  • Location permission
  • Play Services Location Library
  • Device's location should be enabled

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 directly like shown below.

Installing using Artifact Id

Add the following dependency in the app/build.gradle file.

build.gradle

    dependencies {
    	...
      implementation("com.moengage:geofence:$sdkVersion")
    }
    

replace $sdkVersion with the appropriate SDK version

 

VERSION COMPATIBILITY

The geofence artifact should be compatible with the moe-android-sdk artifact you have already added. Ensure you check the version compatibility using the following table and pick the right version for your application.

Configure Geofence

Add the Geofence configuration to the MoEngage.Builder while initializing the SDK using the configureGeofence().

Kotlin Java

    val moEngage = MoEngage.Builder(this, "XXXXXXXX")
        .configureGeofence(GeofenceConfig(isGeofenceEnabled))
        .build()
    MoEngage.initialise(moEngage)

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().

Version Compatibility

Core SDK Version Geofence Version
12.0.00 and above 2.0.0 and above

 

Geofence on Android 12

If your application is targeting API level 31 it is mandatory to define PendingIntent mutability(learn more here). For geofence to work the Pending intent needs to be mutable and the PendingIntent.FLAG_MUTABLE flag is available only starting API level 31. Hence we have a separate artifact for geofence targeting API level 31. 

Apart from the artifact the callbacks etc remain the same as above.

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.geofenceAndroid12)
    }
    

Alternatively, you can add the dependency directly like shown below.

Installing using Artifact Id

Add the following dependency in the app/build.gradle file.

build.gradle

    dependencies {
    	...
      implementation("com.moengage:geofence-android-12:$sdkVersion")
    }
    
Was this article helpful?
0 out of 0 found this helpful