Android

Minimum requirements

First, make sure your app fulfills the Incognia SDK minimum requirements:

Requirement

Version

Minimum Android SDK version

Android API 16

Android Support Library v4

28+

Google Play Services Ads

12.+

Google Play Services Location

12.+

If your project is using AndroidX, you will need to make sure Jetifier is enabled in your gradle.properties file:

gradle.properties
gradle.properties
android.useAndroidX=true
android.enableJetifier=true

Dependencies

Update the top-level build.gradle script of your project to include the Incognia maven repository:

allprojects {
repositories {
maven { url "https://repo.incognia.com/android/" }
...
}
}

In your app-level build.gradle file, add the following dependencies:

Android X
Android Support
Android X
dependencies {
// Required
implementation 'com.incognia:incognia:5.6.2'
// Google Play Services
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
// Compatibility with Support Library
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}
Android Support
dependencies {
// Required
implementation 'com.incognia:incognia:5.6.2'
// Google Play Services
implementation 'com.google.android.gms:play-services-location:16.0.0' // You can use versions from 12.0.0 up to 16.0.0
implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0' // You can use versions from 12.0.0 up to 16.0.0
// Support Library
implementation 'com.android.support:support-v4:28.0.0'
}

After updating your app-level build.gradle, the project must be synced for the changes to take effect.

Update Android manifest

Add the following <uses-permission> tags inside the <manifest> tag of your AndroidManifest.xml file.

AndroidManifest.xml
AndroidManifest.xml
<manifest>
<!-- Required for connectivity access -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Required for location services -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Improves location accuracy and battery consumption -->
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>
<!-- Allows the SDK to restart itself after the device is rebooted -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- For apps targeting Android 10 (29) and higher only -->
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
</manifest>

If you are interested, take a look at why we ask for these permissions using the link below.

Add config file to your project

The Incognia SDK initialization relies on the presence of an incognia.xml file in the main/res/values directory of your project.

Please modify the incognia_app_id field and add it to the main/res/values directory in your Android project.

incognia.xml
incognia.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Your App id-->
<string name="incognia_app_id" translatable="false">YOUR_APP_ID</string>
<!-- Whether SDK logs are enabled -->
<bool name="incognia_log_enabled">true</bool>
<!-- Whether visits tracking is enabled by default after SDK initialization -->
<bool name="incognia_visits_enabled_by_default">true</bool>
<!-- Whether the user needs to provide privacy consent -->
<bool name="incognia_privacy_consent_required">false</bool>
</resources>

Note: Remember to replaceYOUR_APP_IDwith the identifier of the application that our team provided to your company.

The complete list of possible customization keys is shown below.

Key

Description

Type

Required

incognia_app_id

Your Application ID.

string

incognia_log_enabled

Whether logs are enabled.

boolean (true)

incognia_visits_enabled_by_default

Whether visit tracking is enabled by default during the SDK initialization.

boolean (true)

incognia_privacy_consent_required

Whether the user needs to provide privacy consent for the SDK to be initialized.

boolean (false)

incognia_background_wakeup_enabled

Whether background wakeup is enabled.

boolean (true)

Initializing the SDK

Inside the onCreate method of your Application class, insert the following code to initialize the Incognia SDK.

Kotlin
Java
Kotlin
import com.incognia.icg.Incognia
class CustomApplication : Application() {
override fun onCreate() {
super.onCreate()
//Initializes the Incognia SDK
Incognia.init(this)
}
}
Java
import com.incognia.icg.Incognia;
public class CustomApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
//Initializes the Incognia SDK
Incognia.init(this);
}
}

Tips: For instructions on how to create your own implementation of the Application class, please check the official Android documentation.

If the SDK was initialized properly, your Logcat output will contain the following logs.

Logcat
Logcat
I/Incognia: Incognia SDK 5.6.2 is running
I/Incognia: Incognia Location SDK 5.6.2 is running

Request runtime permissions

The previous step started the Incognia SDK but your application still needs to request the location permissions (i.e., ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION) from the user in order to fully unlock the location capabilities of the SDK.

We recommend that the permissions are requested as shown in the Android documentation.

Attention: Without theManifest.permission.ACCESS_FINE_LOCATION, most features will not be available. It is extremely important that the user is asked for permission. If you are targeting Android 10, you also must ask for Manifest.permission.ACCESS_BACKGROUND_LOCATION.

What's next?

From here, you can either complete the full integration with our APIs by using the Installation ID or follow the steps to test the Incognia solution with SDK-only integration. In this mode, you will receive access to a dashboard that displays Incognia's risk scores without needing to integrate the APIs.