Android SDK

Installation

The minSdkVersion version number in your build.gradle should not be less than 24.

To add the SDK to your app, please follow these steps:

  1. This guide covers the Mobile SDK v2.0.0 production release. Release details: https://github.com/UtiqTech/android-sdk/releases/tag/v2.0.0

  2. Add the following dependency to your project’s build.gradle or settings.gradle file under the allprojects block

Groovy

Groovy
allprojects {
   repositories {
      maven {
         url 'https://maven.pkg.github.com/UtiqTech/android-sdk'
         credentials {
            username = GITHUB_USERNAME
            password = GITHUB_TOKEN
         }
      }
   }
}

Kotlin DSL

Kotlin
allprojects {
   repositories {
       maven { 
          url = uri("https://maven.pkg.github.com/UtiqTech/android-sdk")
          credentials { 
             username = GITHUB_USERNAME
             password = GITHUB_TOKEN
          }
       }
   }
} 
  1. Add this dependency com.utiq:utiq-android:2.0.0 to the build.gradle or build.gradle.kts file of your App or module.

Use version 2.0.0 for the API and examples below.

  1. Also, add the following permissions to your manifest file if you didn't' already.

XML
<uses-permission android:name="android.permission.INTERNET"/>
  1. Initialize the SDK

Basic initialization

Assuming you have an Application class registered in AndroidManifest.xml, call the initialize function inside onCreate(), passing the application context and the SDK token provided by us.

Kotlin

Kotlin
Utiq.initialize(this, SDK_TOKEN)

Java

Java
Utiq.initialize(this, SDK_TOKEN);

Please contact onboard@utiq.com to request a new SDK Token for your mobile App.

Initializing with custom options

UtiqOptions() is an optional parameter for SDK initialization. You can initialize the SDK without it, but if you want to enable or disable specific options, configure them in UtiqOptions and pass it to the initializer.

Currently, the only available options are enabling debugging.

Kotlin

Kotlin
val options = UtiqOptions().enableLogging()
Utiq.initialize(this, SDK_TOKEN, options)

Java

Java
UtiqOptions options = new UtiqOptions().enableLogging();
Utiq.initialize(this, SDK_TOKEN, options);


If your app uses OneTrust (or any CMP that internally uses WorkManager), release builds with R8 enabled may crash at startup with an error like:

java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider
Caused by: java.lang.RuntimeException: Failed to create an instance of class androidx.work.impl.WorkDatabase

Fix: Add the following to your app module’s proguard-rules.pro

-keep class androidx.work.** { *; }

Basic usage

Once the SDK is initialized, call its public functions through Utiq. In v2.0.0, fetchIDs() is the recommended identifier API and returns all available records. fetchIdConnectData() remains only as a deprecated single-record compatibility API and will be removed in a future release.

Fetch Utiq identifiers with fetchIDs

Kotlin

Kotlin
Utiq.fetchIDs(dataCallback = { ids ->
    ids.forEach { id -> println("mtid: ${id.mtid}, atid: ${id.atid}, attrid: ${id.attrid}, ttl: ${id.ttl}") }
}, errorCallback = { error ->
    error.printStackTrace()
})

Java

Java
Utiq.fetchIDs(null, ids -> {
    ids.forEach(id -> System.out.println("mtid: " + id.getMtid() + ", atid: " + id.getAtid() + ", attrid: " + id.getAttrid() + ", ttl: " + id.getTtl()));
} , error -> {
    error.printStackTrace();
});


Kotlin

Kotlin
Utiq.fetchIDs(dataCallback = { ids ->
    ids.forEach { id -> println("mtid: ${id.mtid}, atid: ${id.atid}, attrid: ${id.attrid}, ttl: ${id.ttl}") }
}, errorCallback = { error ->
    error.printStackTrace()
})

Java

Java
Utiq.fetchIDs(null, ids -> {
    ids.forEach(id -> System.out.println("mtid: " + id.getMtid() + ", atid: " + id.getAtid() + ", attrid: " + id.getAttrid() + ", ttl: " + id.getTtl()));
} , error -> {
    error.printStackTrace();
});

Dedicated guidelines for Utiq Privacy Requirements and Consent Experience on Mobile Apps can be found at this page Consent Experience on Mobile App

The SDK does not provide a built-in consent dialog. Your application must collect user consent using either a standard Consent Management Platform (CMP) or a custom pop-up that matches your app's look and feel.

User consent for the Utiq technology must be in place before calling fetchIDs().

While the pop-up may match the look and feel of your app, the consent description must follow our guidelines, which can be found here.

Kotlin

Kotlin
Utiq.rejectConsent()

Java

Java
Utiq.rejectConsent(null, null);

This function can be used to reject the user’s consent if he changed his mind, or to reset the consent status.

You don’t need to provide success/failure closures, unless you want to log the outcome.

Kotlin

Kotlin
Utiq.rejectConsent(successCallback = { ... }, errorCallback = { error -> ... })

Java

Java
Utiq.rejectConsent(() -> { ... }, error -> { ... });

consenthub URL

If you need to access the ConsentHub URL from within the mobile app (for example, in a web view), you can do so by calling the function that returns the ConsentHub URL.

Kotlin

Kotlin
val consentHubUrl = Utiq.getConsentHubUrl()

Java

Java
try {
    String consentHubUrl = Utiq.getConsentHubUrl(null);
} catch (Throwable error) {
    // Handle the error
}

Error handling

Functions with callbacks described in the previous sections include both success and failure callbacks (or closures). APIs declared as throwing, including the ConsentHub URL function, report synchronous failures directly and must be handled using the platform's exception-handling mechanism. The failure callback returns a custom error that is specific to the function. You can use this error to take a defined action based on the error type. APIs declared as throwing, including the ConsentHub URL function, report synchronous failures directly and must be handled using the platform's exception-handling mechanism.

All listed errors are UtiqError values that inherit from Throwable. Mobile SDK v2.0.0 also includes InvalidIdConnectBaseURLException (-1989) for an invalid ID Connect base URL and EmptyIdGraphException (-1973) when identification completes without any ID graph records.

Displaying errors from the SDK directly to the end user is not recommended. Instead, errors are returned so that developers can handle them appropriately and take the necessary actions based on the error type.


Error

Description

HttpException

Represents an HTTP exception that includes an error message and a status code.

InvalidSdkTokenException

Indicates that an invalid token was used to initialize the SDK.

SdkTokenCanNotBeEmptyException

This error is thrown when an empty token is passed to the SDK’s initializer.

SdkNotInitializedException

This error is thrown if you attempt to call any SDK function before the SDK has been initialized.



FailedToFetchConfigsException

This error is thrown when the SDK fails to fetch configuration data from the server and has no local configuration file to fall back on. This situation occurs if there are no cached configurations from a previous session, preventing the SDK from initializing correctly.

UtiqConsentExpiredException

This error is thrown when the user’s previously saved consent has expired.

TemplateDataUrlNotFoundException

This error is thrown when the templateDataUrl is missing from the config API response.

InvalidConsentVersionsException

This error is thrown when the consent version is invalid.


UnKnowUserStatusException

When starting the Utiq identification flow, the user status must be one of the following: NEW, OK, or NotCreated. If the status is any value other than the expected one, this error will be thrown.

UnKnownConnectionTypeException

Unknown connection type

EmptySetCookieHeaderException

Indicates that the Set-Cookie header is missing from the response header.

MnoIneligibleException

Telco (SIM card operator) is not supported by Utiq.

UtiqConsentNotSetException

User has not provided consent or has not been prompted to accept or reject it.


UserOptedOutFromUtiqException

The user revoked consent in Consent Hub. The SDK clears cached identification data. Disable Utiq in the CMP, clear app state that depends on Utiq IDs, and do not fetch again unless the user later grants valid consent.

InvalidTelcoUseCaseException

Indicates that the SIM operator belongs to a use case that is unknown to Utiq.

MnoUrlNotFoundException

Indicates that the mobile MNO URL was not found.

DataValueNotFoundException

Indicates that the data value was not found.

DataDomainNotFoundException

Indicates that the data domain was not found.

NetworkIdentificationException

Indicates that the Network identification failed. Handle this as a technical or eligibility failure; do not automatically disable Utiq consent in the CMP.

IdConnectDataNotFoundException

Indicates that ID Connect data was not found.

GenericException

Indicates an error that does not match any of the other errors listed in this table.

Support and bug reporting

If you have suggestions, want to report a bug, or have any other inquiries, please contact onboard@utiq.com