Add Geofences
1. Add Google Play Service Location dependency to your build
To be compatible with the current version of the SDK, replace {currentSupportedVersion} with 21.0.1. This version of Google Play Services has been tested with the latest version of the SDK. Behavior is not guaranteed if you use a different version of Google Play Services.
2. Add these permissions to your application’s AndroidManifest.xml
3. Enable geofence messaging during SDK initialization
To troubleshoot information related to geofence messaging in the InitializationStatus that is returned during the SDK’s initialization call, see initialization status documentation.
4. Request location permission
To enable geofence messaging, request the required location permissions from your users at runtime. For users on devices running Android Q, request both the ACCESS_FINE_LOCATION
and ACCESS_BACKGROUND_LOCATION
permissions. For users on devices older than Android Q, you can request only the ACCESS_FINE_LOCATION
permission.
See Request App Permissions for more information on requesting runtime permissions. See Android Q privacy change documentation for more information on this change.
5. Enable geofence messaging at runtime
Once the permission is granted you can enable geofence notification by calling enableGeofenceMessaging()
.
You can disable geofence notifications by calling disableGeofenceMessaging()
.
MobilePush prevents your app from displaying a geofence message with an empty alert. If you include AMPscript in your message that returns no content or an empty string, the mobile app doesn’t display that message.