Android SDK implementation guidelines

By Bart Muskala

Updated 3 months ago

This repository contains the Android Accurat SDK. You can find the instructions to integrate the Accurat SDK into your Android app below.

Content

  • Requirements
  • Configure project
  • Add SDK to project
  • Integrate SDK into app
  • Contact

Requirements

  • Android minSdkVersion 19+ (KitKat)
  • Android targetSdkVersion 27+ (Oreo)

Configure project

Accurat requires the following permissions to be included in your app manifest:

PermissionReason
android.permission.ACCESSCOARSELOCATIONFor location services
android.permission.ACCESSFINELOCATIONFor location services
android.permission.INTERNETTo send API requests
android.permission.ACCESSWIFISTATETo access information about Wi-Fi networks
android.permission.ACCESSNETWORKSTATETo check for a network connection
android.permission.RECEIVEBOOTCOMPLETEDTo restart Accurat after device reboots
com.google.android.gms.permission.ACTIVITY_RECOGNITIONTo detect the user's activity


Add SDK to project

Project build.gradle

Add the following in your Android project's build.gradle file:

allprojects {
    repositories {
        maven {
            url: 'https://jitpack.io'
            credentials { username 'YOUR JITPACK ACCESS TOKEN' }
        }
    }
}

Module build.gradle

Add the following in your Android project's module build.gradle file:

dependencies {
    implementation('com.gitlab.accuratai:sdk-android:[VERSION]@aar') {
        transitive=true
    }
}

Replace [VERSION] with the version tag of your choosing (see changelog.md), like so:

dependencies {
    implementation('com.gitlab.accuratai:sdk-android:1.0.3@aar') {
        transitive=true
    }
}

The Accurat SDK depents on the following libraries:

  • Google's appcompat Support library version 27.1.1
  • Play Services Location library version 15.0.1
  • Play Services Ads library version 15.0.1
  • Android JetPack's WorkManager library version 1.0.0-alpha07
  • Volley library 1.1.0

These libraries will automatically be included as transitive dependencies.

Integrate SDK into app

MainActivity.java

Initialize SDK (required)

In your main activity, start by initialising Accurat in your onCreate()-method:

Accurat.initialize(this, "ACCURAT_USERNAME", "ACCURAT_PASSWORD", "ACCURAT_KEY");

where ACCURAT_USERNAME and ACCURAT_PASSWORD are strings containing our Accurat username and password while ACCURAT_KEY is the key required for activating the SDK.

Permissions (required)

Next, pass along permission request results to Accurat so we can show permission dialogs and handle them:

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permission, @NonNull int[] grantResults) {
    boolean handledByAccurat = ConsentManager.onRequestPermissionResult(requestCode, permissions, grantResults);

    // Your code
}

Start Tracking (required)

Finally, call Accurat's startTracking-method to ask a user's consent and start tracking:

Accurat.startTracking(this, onComplete);

where this is an Activity and onComplete is an AccuratProcessCallback which lets you know whether Accurat could be started or not. Possible reasons for Accurat not being able to start are: No internet connection or the user refused one or more consents. It is recommended to implement this method in your main activity's onCreate()-method.

Stop Tracking (optional)

To stop Accurat, simply call the stopTracking-method:

Accurat.stopTracking();

Is tracking enabled? (optional)

If you want to know if Accurat is tracking the user's location, call the isTrackingEnabled()-method.

Accurat.isTrackingEnabled();

Set language (optional)

If you want to change the language of the user, you can update the language. This language will i.e. be used in the consent popups. When no language is set, the device language is used, or English if the device language is not supported.

Accurat.setLanguage(language);

where language is one of AccuratLanguage.NL, AccuratLanguage.FR or AccuratLanguage.EN.

GDPR (optional)

Before tracking a user's location, the user is asked to authorise location permissions for the app and give consent to use his location data.

If you want to start the consent flow seperatly from the tracking, call the askConsents()-method (this is also automatically called by the tracking):

Accurat.askConsents(activity, onComplete);

where activity is an Activity in which the consent dialogs will be shown and onComplete is an AccuratProcessCallback which lets you know whether all consents where approved.

If you want to get the state of a consent, call the getConsentState()-method and provide a consent type:

Accurat.getConsentState(consentType);

where consentType is one of ConsentType.TRACKING.

If you want to update the state of a consent, call the updateConsent()-method and provide a consent type and consent state:

Accurat.updateConsent(consentType, consentState);

where consentType is one of ConsentType.TRACKING and consentState is one of ConsentState.UNKNOWN, ConsentState.APPROVED or ConsentState.REFUSED.

Contact

Do you have any questions? E-mail us at steven@accurat.ai.

Did this answer your question?