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:
-
This guide covers the Mobile SDK v2.0.0 production release. Release details: https://github.com/UtiqTech/android-sdk/releases/tag/v2.0.0
-
Add the following dependency to your project’s
build.gradleorsettings.gradlefile under theallprojectsblock
Groovy
allprojects {
repositories {
maven {
url 'https://maven.pkg.github.com/UtiqTech/android-sdk'
credentials {
username = GITHUB_USERNAME
password = GITHUB_TOKEN
}
}
}
}
Kotlin DSL
allprojects {
repositories {
maven {
url = uri("https://maven.pkg.github.com/UtiqTech/android-sdk")
credentials {
username = GITHUB_USERNAME
password = GITHUB_TOKEN
}
}
}
}
-
Add this dependency
com.utiq:utiq-android:2.0.0to thebuild.gradleorbuild.gradle.ktsfile of your App or module.
Use version 2.0.0 for the API and examples below.
-
Also, add the following permissions to your manifest file if you didn't' already.
<uses-permission android:name="android.permission.INTERNET"/>
-
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
Utiq.initialize(this, SDK_TOKEN)
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
val options = UtiqOptions().enableLogging()
Utiq.initialize(this, SDK_TOKEN, options)
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
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
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
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
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();
});
Utiq Consent
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.
Reject consent
Kotlin
Utiq.rejectConsent()
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
Utiq.rejectConsent(successCallback = { ... }, errorCallback = { error -> ... })
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
val consentHubUrl = Utiq.getConsentHubUrl()
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 |
|---|---|
|
|
Represents an HTTP exception that includes an error message and a status code. |
|
|
Indicates that an invalid token was used to initialize the SDK. |
|
|
This error is thrown when an empty token is passed to the SDK’s initializer. |
|
|
This error is thrown if you attempt to call any SDK function before the SDK has been initialized. |
|
|
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. |
|
|
This error is thrown when the user’s previously saved consent has expired. |
|
|
This error is thrown when the |
|
|
This error is thrown when the consent version is invalid. |
|
|
When starting the Utiq identification flow, the user status must be one of the following: |
|
|
Unknown connection type |
|
|
Indicates that the |
|
|
Telco (SIM card operator) is not supported by Utiq. |
|
|
User has not provided consent or has not been prompted to accept or reject it. |
|
|
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. |
|
|
Indicates that the SIM operator belongs to a use case that is unknown to Utiq. |
|
|
Indicates that the mobile MNO URL was not found. |
|
|
Indicates that the data value was not found. |
|
|
Indicates that the data domain was not found. |
|
|
Indicates that the |
|
|
Indicates that ID Connect data was not found. |
|
|
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