For Android
Integration Steps
To integrate DuopenGeofence into your Android project, follow these steps:
1. Adding Credentials to Access the Library
To ensure your project can access the DuopenGeofence library, update your settings.gradle file with the required credentials and Maven repository configuration.
Make sure the dependencyResolutionManagement block is properly configured as follows:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google() // Standard Google repository
mavenCentral() // Central repository for dependencies
maven {
// Maven repository for Duopen Geofence library
name = "duopen-geofence-android"
url = uri("https://maven.pkg.github.com/duopen-tecnologia/duopen-geofence-android")
credentials {
// Replace <YOUR_CREDENTIAL> with your actual password or token
username = "duopen-tecnologia"
password = "<YOUR_CREDENTIAL>"
}
}
}
}NOTE:
Replace
<YOUR_CREDENTIAL>with the actual password or token provided by us.Avoid hardcoding sensitive credentials directly into your codebase. Instead, use secure methods such as environment variables or a secrets management tool.
2. Add the Duopen Geofence Library
Include the following line in the build.gradle file of your app:
3. Add Required Dependencies
The following libraries are also necessary for DuopenGeofence to works correctly. Add them to the build.gradle file:
4. Required Permissions
The library requires specific permissions to works. These permissions must be explicitly requested and granted by the user:
ACCESS_FINE_LOCATION: To get the precise location when the app is active.
NOTE: Users must select the Fine or Precise option. We advise to use popups or some sort of modal to guide the user before the permission request.
ACCESS_BACKGROUND_LOCATION: To detect geofence transitions in the background.
NOTE: Users must select the Allow all the time option. We advise to use popups or some sort of modal to guide the user before the permission request.
Additional permissions, which are automatically included in the AndroidManifest.xml during the library’s integration, include:
INTERNET: Ensures connectivity for the main app.
RECEIVE_BOOT_COMPLETED: Detects device restarts to maintain geofence functionality.
NOTE: Since the library’s permissions are merged into the main app’s AndroidManifest.xml, manual addition is unnecessary.
5. Library Functions
Necessary Imports:
The library has only one function accessible by the developer. After permissions are granted, initialize the library using:
Parameters:
context: Preferably the
MainActivitycontext.accessKey: A UUID provided for each application, mapping geofences to specific locations.
CPF: A unique identifier for logged users (e.g., “12345678900”).
NOTE: Please ensure that you are passing the correct user's CPF stored in your app.
Mode:
Mode.DEBUG: Sends location transitions to test endpoints (data not stored).Mode.RELEASE: Stores data in the production database. EnsureMode.RELEASEis used for production builds.NOTE: Please ensure that if you are running on an emulator, use the mode.DEBUG parameter.
Return:
The function does not have a return
Example of Usage
Developers must ensure users grant both FINE and BACKGROUND location permissions.


Below is an implementation example in a generic MainActivity:
Testing the Duopen Geofence Library in Android Studio Emulator
Enable GPS in the Android emulator.
Open the Device Manager in Android Studio and select the emulator.
In the 3 dots that appear on the top, click to access the Extended Controls > Location and set a location or route passing through the geofence.
Open Google Maps on the emulator to force geofence updates. Note that updates may take 5-10 minutes based on the user’s last known location.
You will be able to see the logs like the following if everything is working:
EVENT ~ Location: test-location | CPF: 12312312312| Status: IN | Mode: DEBUG
Last updated