Module responsible for monitoring the user’s geographic location. This module runs in the background and monitors the places visited by users.
To initialize the geolocation, the application needs the user’s permission, as shown in the example below (Feel free to implement it as you wish).
Your Activity must implement ActivityCompat.OnRequestPermissionsResultCallback.
protected void requestGeoTrackingPermissions() {
// Verify Google Play Services
final GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
final int result = googleAPI.isGooglePlayServicesAvailable(getApplicationContext());
if (result != ConnectionResult.SUCCESS) {
if (googleAPI.isUserResolvableError(result)) {
googleAPI.getErrorDialog(this, result, 9000).show();
}
// User must update his Google Play Services
return;
}
// Verifica permissão de geolocalização
if (ActivityCompat.checkSelfPermission(getApplicationContext(),
android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(getApplicationContext(),
android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// Requisitar permissão de geolocalização
ActivityCompat.requestPermissions(this, new String[]{
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION
}, 200);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (200 == requestCode && grantResults.length > 0) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission granted, start MDM GeoBehavior
MDMGeoBehavior.start(getApplicationContext());
ActivityCompat.requestPermissions(this, new String[]{
android.Manifest.permission.ACCESS_BACKGROUND_LOCATION}, 2);
} else {
// Permission not granted
}
}
}
Ask user’s permission:
MDMCore.askPermissionFullDialog(this, new MDMCore.PermissionListener() {
@Override
public void onPermissionResponse(boolean response) {
requestGeoTrackingPermissions();
}
});
And once the user’s permission is granted, call again GeoBehavior module initialization:
MDMGeoBehavior.start(getApplicationContext());
Opt-out
To opt-out module, just call the following command:
MDMGeoBehavior.setOptOut(getApplicationContext(), true);
To undo the module opt-out, just call the following command:
MDMGeoBehavior.setOptOut(getApplicationContext(), false);