Skip to main content

UID2 SDK for Android Reference Guide

You can use the UID2 SDK for Android to facilitate the process of establishing client identity using UID2 and retrieving advertising tokens on Android devices.

The following Android-related plugins, and associated documentation, are also available.

To use the Google Mobile Ads (GMA) SDK to send UID2 tokens as secure signals in ad requests from Android appsUID2 GMA Plugin for Android Integration Guide
To use the Google Interactive Media Ads (IMA) SDK for Android to send UID2 tokens as secure signals in ad requests from Android appsUID2 IMA Plugin for Android Integration Guide


This SDK simplifies integration with UID2 for any publishers who want to support UID2 for apps running on Android devices. The following table shows the functions it supports.

Encrypt Raw UID2 to UID2 TokenDecrypt UID2 TokenGenerate UID2 Token from DIIRefresh UID2 Token
Not supportedNot supportedNot supportedSupported

SDK Version

This documentation is for the UID2 Android SDK version 0.5.0 and later.

For information about specific release versions, see


The UID2 Android SDK is designed to manage UID2 identity on behalf of Android apps. It enables UID2 identity to be persisted across app lifecycles by securely storing the identity on a device via platform-native encryption tools.

By default, the SDK automatically refreshes UID2 identity based on expiration dates. However, you can disable this to allow implementing apps to manage the UID2 identity lifecycle manually.

GitHub Repository/Binary

This SDK is in the following open-source GitHub repository:

The binary is published on Sonatype:

Minimum Requirements

Minimum requirements for this SDK are as follows:

  • Android Studio version: 2022.1.1 Patch 2+
  • Minimum target Android version: 4.4+ / API 19+ (SDK) 5.0+ / API 21+ (Dev-App)


There are two options for installing the Android UID2 SDK:

Installing with Gradle

To install with Gradle, add the SDK as a dependency in the build.gradle file:

implementation 'com.uid2.uid2-android-sdk:0.5.0'

Installing with Maven

To install with Maven, add the SDK as a dependency in the pom.xml file:


Usage Guidelines

The initial UID2 Identity must be generated by the implementing application and then passed into the UID2 SDK. Because of security requirements, the UID2 Mobile SDKs cannot create new UID2 identities.

The UID2 Mobile SDKs can perform refreshes of UID2 identities, after an Identity is established. This is because the refresh functionality relies on the refresh tokens that are part of the UID2 Identity.

The UID2Manager singleton is the primary developer API for the UID2 Android and iOS SDKs. It is responsible for storing, refreshing, and retrieving UID2 Identity.

For Android, you must initialize the UID2Manager manually before you can use it. See Android Initialization.

UID2Manager API

This section includes the functions and variables that are part of the UID2Manager API.


The following functions are available as part of the UID2Manager API:


Sets the UID2 Identity to be managed by the SDK.


Resets or removes the UID2 Identity currently being managed by the SDK.


Manually refreshes the UID2 Identity being managed by the SDK.


If the current UID2 Identity is valid, this function returns the UID2 token (advertising token).


Toggle for automatic refresh functionality.


The following variables are available as part of the UID2Manager API:


The Identity variable stores and returns the current UID2Identity data object being managed by the SDK.


The identityStatus variable stores and returns the status of the current UID2 Identity being managed by the SDK.

Android Initialization

The Android implementation expects the singleton to be initialized before use. This does two things:

  • It allows for easier access later.

  • It allows the consuming application to potentially provide its own network instance, responsible for making requests.

The initialization can be done during the creation of the APPLICATION instance, as shown in the following example:

class MyApplication : Application() {
override fun onCreate() {
// Initialize the UID2Manager class. Use DefaultNetworkSession rather than providing our own
// custom implementation. This can be done to allow wrapping something like OkHttp.

Code Samples

The following code samples provide examples of performing specific activities relating to managing UID2 with the UID2 Android SDK.

Set the Initial UID2 Identity:

UID2Manager.getInstance().setIdentity(identity: UID2Identity)

Get the UID2 token (advertising token) to pass to the Advertising SDK: