Geofence & Location
Netmera SDK Location Usage on Android
By default, the Netmera SDK does not gather any location information from the device. To use geofence push notifications and location-based targeting, you must enable location tracking in your application.
Geofence Push Notifications on Android 10 and Above
On Android 10 and later, geofence push notifications require background location access. However, Android does not allow apps to request this permission directly in the app. Instead, users must manually enable "Allow all the time" in the system settings.
Best Practice: Before redirecting users to settings, display an explanatory message about why location access is needed. You can use Netmera widgets to communicate this effectively. You may see the next page Background Location Permission on how to create these widgets to ask for location permissions.
Step 1: Add Required Permissions
In your AndroidManifest.xml file, add the following permissions:
Step 2: Request Permissions at Runtime
For Android 6.0 (API Level 23) and later, location permission must be requested while the app is running. Netmera provides a built-in permission request flow:
After calling this method, the default permission dialog will appear if the app does not already have location access. Once the user grants permission, Netmera will handle location operations based on your settings in the Netmera Dashboard.
Step 3: Enable Location History
To track user location, enable Location History in the Netmera web panel: Developers > App Info > App Config > Location History Enabled
Step 4: Set Maximum Active Geofence Regions
To limit the number of active geofences, use the following method:
If you set a value greater than 95 or less than 0, it will be reset to the default (95).
Step 5: Configure Location Hardware Requirements (Optional)
If your app requires location-based services but should still be visible on devices without GPS hardware, add the following declarations in AndroidManifest.xml:
Troubleshooting
1. Crash Resolution: Update to gms:play-services-location Version 21.0.1
If you encounter the following crash and are using gms:play-services-location
, it is advisable to upgrade to version 21.0.1.
2. Geofence Update Events: Common Causes and Solutions
The Netmera SDK triggers the Geofence Update event when there is a change in the geofence area, prompted by the operating system. However, if the operating system does not trigger this event, you may not see the geofence update events. This can occur due to various reasons such as operating system limitations or device settings.
Last updated
Was this helpful?