Skip to main content

Location

Location is one of the risk parameters that can be sent to the server.

Enable location

To enable collection of location by the Encap SDK, you need to carry out the following steps:

  1. In your application configuration, ensure that ENABLED_RISK_DATA is set to ALL, or that it contains Location.
  2. In the app manifest, ensure that the following location permissions are inserted:
    Example: Location permissions in app manifest
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  3. For Android 10 and higher, you should consider adding the following:
    Example: Addition for Android 10 and higher
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
    Note

    The permission ACCESS_BACKGROUND_LOCATION is not necessary for foreground location collection. Be aware that this permission can be denied by the end-user.

The Encap SDK does not request Android system permissions. This means that the application using the Encap SDK needs to implement that request.

Want to learn more?

To learn how to request system permissions in your application, you can follow the instructions in the Android developer documentation.

Disable location

To disable location, you need to remove the following location permissions from the app manifest file:

Example: Disable location by removing permissions
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>

Enable location (excluding the Encap SDK)

You may have a use case where you need to disable collecting location data for the Encap SDK, but need to keep location permissions for the rest of the app.

To do this, you need to:

  1. Keep the location permissions in app manifest.
  2. Remove Location from ENABLED_RISK_DATA in your application configuration, and/or set locationEnabled flag in the EncapConfig to false.

Enable Google Play Services location

By default, when location is enabled for the Encap SDK, the library uses the platform version of location.

If you want to enable the Google Play Services location, then add the dependency to your app. Once you have done this, the library then picks it up and enables it for all supported Android versions.

Example: Add dependency to your app
dependencies {
implementation("com.google.android.gms:play-services-location:21.3.0")
}

Prevent SDK location update requests

By default, when location permission is granted, the Encap SDK requests location updates:

  • Whenever an EncapConfig is set.
  • During most SDK operations.

If you want to prevent the Encap SDK from requesting location updates, then you can use the locationEnabled flag in the EncapConfig. This allows you to avoid unnecessary battery consumption if your app does not use any features from the Encap SDK that rely on the device's location.

Important

If you disable location updates while location, geofencing, or SSID/BSSID features are enabled, then it may result in unintended behaviour.