• Platforms
  • Partners
  • Forums
  • TLC Tealium Learning Center Tealium Learning
    Community
  • Discussions & Ideas Dicussions & Ideas
  • Product Guides Product Guides
  • Knowledge Base Knowledge Base
  • Developer Docs Developer Docs
  • Education Education
  • TLC Blog TLC Blog
  • Support Desk Support Desk
  • CDH Customer Data Hub Customer Data Hub

Table of Contents

  • Requirements
  • Sample Apps
  • Get the Code
  • Install
    • Maven
    • Manual
  • Initialize
  • Log Level
  • Cookies
  • Event Batching
  • Multiprocess Apps
ANDROID JAVA

Install

Learn to install the Tealium SDK for Android (Java).

Requirements

  • Android Studio
  • Android (KitKat/4.4+ / API Level 19+)
  • Tealium iQ Mobile Profile
  • Tealium Customer Data Hub account

Sample Apps

To help to familiarize yourself with our library, tracking methods, and best practice implementation, explore the Tealium for Android sample apps.

Get the Code

Clone the Tealium Android library. Cloning the library, rather than downloading, makes it easier to update to future releases.

See the Tealium API for a complete listing of Tealium classes and methods for Android.

Install

Install the Tealium SDK for Android with Maven, or manually.

Maven

To install Tealium for Android library with Maven (recommended):

  1. Add the Tealium Maven URL to your project’s top-level build.gradle file:

    allprojects {
      repositories {
        jcenter()
        maven {
          url "https://maven.tealiumiq.com/android/releases/"
        }
      }
    }
  2. In your project module’s build.gradle file, add the following Maven dependency:

    dependencies {
      implementation 'com.tealium:library:5.8.0'
    }

Manual

To install Tealium for Android library manually:

  1. Add flatDir to your project root build.gradle file:

    allprojects {
      repositories {
         jcenter()
         flatDir {
             dirs 'libs'
         }
      }
    }
  2. Add tealium-5.x.x.aar to <PROJECT_ROOT>/<MODULE>/libs.

  3. Add the Tealium library dependency to your build.gradle file:

    dependencies {
      implementation(name:'tealium-5.6.1', ext:'aar')
    }

Initialize

To initialize, make the following changes in app’s onCreate() method:

  1. Create instance of the Tealium.Config object:

    Tealium.Config tealConfig = Tealium.Config.create(
        this,
        "ACCOUNT",
        "PROFILE",
        "ENVIRONMENT");
  2. Call any additional needed methods to set the configuration data such as setDatasourceId():

    tealConfig.setDatasourceId("DATASOURCE_ID");
  3. Call the setupInstance() method to setup the app’s lifecycle instance:

    LifeCycle.setupInstance("INSTANCE_NAME", config, true);
  4. Call the createInstance() method to create the Tealium instance, passing the configuration instance as a constructor argument:

    tealium = Tealium.createInstance("INSTANCE_NAME", tealConfig);

When Collect is enabled in versions 5.5.1+, data is sent to the profile provided in Tealium.Config object. In previous versions, data is sent to the default profile ("main")

Log Level

The log level is controlled by the remote publish settings and is inferred from the environment set in the initialization.

In versions 5.3.1+, it is possible to override the log level locally with the setForceOverrideLogLevel() method as shown in the following example:

tealConfig.setForceOverrideLogLevel("LOG_LEVEL");

Cookies

Enabling cookies is required if you have enabled Tag Management in your mobile profile.

Add the following code, after the initialization statement, to activate cookie management.

config.getEventListeners().add(createCookieEnablerListener());
private static WebViewCreatedListener createCookieEnablerListener() {
    return new WebViewCreatedListener() {
        @Override
        public void onWebViewCreated(WebView webView) {
            final CookieManager mgr = CookieManager.getInstance();
            // Accept all cookies
            mgr.setAcceptCookie(true);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mgr.setAcceptThirdPartyCookies(webView, true);
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
                CookieManager.setAcceptFileSchemeCookies(true);
            }
            Log.d(TAG, "WebView " + webView + " created and cookies enabled.");
        }
    };
}

This code allows the tag management Webview to accept first-party, third-party, and file scheme cookies.

In versions 5.1.0+, CookieManager is enabled by default. In versions 5.0.4 and below, CookieManager is disabled by default.

Event Batching

To enable event batching, go to the Mobile Publish Settings and set the batch size to a value greater than 1. Events are dispatched when the number of events in the queue equals the batch size.

The dispatch of events can also be triggered based on the batch timeout setting. This setting ensures that, when the batch size is not reached, the queue is still dispatched after an elapsed period of time. Set the batch timeout by calling the method setSecondsBeforeBatchTimeout().

To override the batch size and batch timeout checks, flush the queue immediately by calling the method requestFlush().

If the device is offline or has the Consent Manager enabled, the flush override has no effect.

Multiprocess Apps

Android 9+ Multiprocess Applications

Android 9 introduced a behavior change around WebView data directories in multiprocess applications. In this change, a WebView no longer shares a single data directory across multiple processes. Typically, you’ll want to have all your Activities that use a WebView in the same process.

If implementing more instances of WebView in more than one process, and you’re using Tealium’s Tag Management solution, we recommend calling setDataDirectorySuffix before creating an instance of Tealium to prevent the app from crashing.

If you need to access Tealium’s tag management cookies and web data, copy it between processes using the getCookie() and setCookie() methods of the CookieManager class.

Addition Reading: Web-based data directories separated by process

Track

 
  • Mobile
  • Getting Started
    • Overview
    • Quick Start Guide
    • Mobile Concepts
    • Client-Side
    • Server-Side
    • Tracking Webviews
    • Data Layer
    • Consent Management
    • Event Batching
    • User Location and Geofencing
    • Deep Links
    • Timed Events
    • Trace
    • Hosted Data Layer
    • Feature Comparison
    • Troubleshooting
  • Remote Commands
    • Overview
    • How It Works
    • Integrations
      • AppsFlyer
      • Braze
      • Contentsquare
      • Facebook
      • Firebase
      • Kochava
      • Usabilla
  • Android (Java)
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • Consent Management
    • Module List
      • Ad Identifier Module
      • Crash Reporter Module
      • Install Referrer Module
      • Lifecycle Tracking Module
      • Location Module
      • Optimizely X Tracking Module
    • Android TV
    • Android Wear
    • API Reference
      • ConsentManager
      • DataSources
      • Lifecycle
      • Tealium
      • Tealium.Config
      • TealiumLocation
    • Release Notes
  • Android (Kotlin)
    • Overview
    • Install
    • Track
    • Data Layer
    • Consent Management
    • Identity Resolution
    • Module List
      • Ad Identifier Module
      • Collect Module
      • Collectors Module
      • Crash Reporter Module
      • Install Referrer Module
      • Lifecycle Tracking Module
      • Location Manager Module
      • RemoteCommands Module
      • Tag Management Dispatcher Module
      • Visitor Service Module
    • Android TV
    • API Reference
      • ConsentCategory
      • ConsentManager
      • CurrentVisit
      • DataLayer
      • Lifecycle
      • LocationManager
      • Tealium
      • TealiumConfig
      • VisitorProfile
      • VisitorService
    • Release Notes
  • Cordova
    • Overview
    • Install
    • Track
    • Data Management
    • Module List
      • Ad Identifier Module
      • Crash Reporter Module
      • Install Referrer Module
    • API Reference
    • Release Notes
  • Flutter
    • Overview
    • Install
    • Track
    • Consent Management
    • Data Management
    • API Reference
    • Release Notes
  • iOS (Objective-C)
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • Consent Management
    • Tag Management
    • Module List
      • Lifecycle Tracking Module
    • tvOS
    • watchOS
    • API Reference
    • Release Notes
  • iOS (Swift) 1.x
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • App Extensions
    • Identity Resolution
    • Consent Management
    • Modules
    • Module List
      • AppData Module
      • Attribution Module
      • AutoTracking Module
      • Collect Module
      • Connectivity Module
      • CrashReporter Module
      • DataSource Module
      • DefaultStorage Module
      • Delegate Module
      • DeviceData Module
      • DispatchQueue Module
      • FileStorage Module
      • Lifecycle Module
      • Location Module
      • Logger Module
      • PersistentData Module
      • RemoteCommands Module
      • TagManagement Module
      • VisitorService Module
      • VolatileData Module
    • Feature Comparison
    • Working with Objective-C
    • API Reference
      • TealiumConfig
      • TealiumConsentCategories
      • TealiumConsentManagerDelegate
      • TealiumConsentManager
      • TealiumInstanceManager
      • TealiumPersistentData
      • TealiumVolatileData
      • Tealium
    • Release Notes
  • iOS (Swift) 2.x
    • Overview
    • Install
    • Track
    • Data Layer
    • Consent Management
    • App Extensions
    • Identity Resolution
    • Modules
    • Module List
      • AppData Module
      • Attribution Module
      • AutoTracking Module
      • Collect Module
      • Connectivity Module
      • CrashReporter Module
      • DeviceData Module
      • Lifecycle Module
      • Location Module
      • RemoteCommands Module
      • TagManagement Module
      • VisitorService Module
    • Working with Objective-C
    • API Reference
      • Tealium
      • TealiumConfig
      • TealiumConsentCategories
      • TealiumConsentManager
      • TealiumDataLayer
      • TealiumInstanceManager
    • Release Notes
  • NativeScript
    • Overview
    • Install
    • Track
    • API Reference
      • Tealium
      • TealiumConfig
    • Release Notes
  • React Native 1.x
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • React Native 2.x
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • Unity
    • Overview
    • Install
    • Track
    • API Referencee
  • Xamarin
    • Overview
    • Install
    • Track
    • Data Management
    • Consent Management
    • API Reference
    • Release Notes
  • Web
  • Getting Started
    • Overview
    • Quick Start Guide
    • Web Concepts
  • Adobe Launch
    • Overview
    • Install
    • Data Layer
  • AMP
    • Install
    • Track
    • Data Layer
    • Overview
  • Angular
    • Install
    • Track
    • API Reference
    • Overview
  • Google Tag Manager
    • Overview
    • Data Layer
    • Install
  • JavaScript (Web)
    • Install
    • Track
    • Data Layer
    • Overview
    • Universal Data Object (utag_data)
    • Universal Tag (utag.js)
    • Data Layer Object (b)
    • Single-Page Applications
    • Settings
    • Debugging
    • API Reference
      • Cookie Functions
      • GDPR Functions
      • Tracking Functions
      • Utility Functions
    • Release Notes
  • Server
  • C#
    • Overview
    • Install
    • Track
    • Data Layer
    • API Reference
    • Release Notes
  • HTTP API
    • Overview
    • Endpoint
    • Data Layer
  • Java
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • Node
    • Overview
    • Install
    • Track
    • API Reference
  • Python
    • Overview
    • Install
    • Track
    • API Reference
  • Roku
    • Overview
    • Install
    • Track
    • API Reference
  • Ruby
    • Overview
    • Install
    • Track
    • API Reference

Was this article helpful?

This page was last updated: August 17, 2020       Thank you for your feedback!
  • Platforms
  • Partners
  • Forums
  • Mobile
  • Getting Started
  • Remote Commands
  • Android (Java)
  • Android (Kotlin)
  • Cordova
  • Flutter
  • iOS (Objective-C)
  • iOS (Swift) 1.x
  • iOS (Swift) 2.x
  • NativeScript
  • React Native 1.x
  • React Native 2.x
  • Unity
  • Xamarin
  • Web
  • Getting Started
  • Adobe Launch
  • AMP
  • Angular
  • Google Tag Manager
  • JavaScript (Web)
  • Server
  • C#
  • HTTP API
  • Java
  • Node
  • Python
  • Roku
  • Ruby