Android Integration

The Audience SDK is a security-centric tool enabling mobile apps to access location-based advertising.

Overview

The Audience SDK segments mobile app users on-device to offer them relevant location-based ads. Due to the security-centric approach, location and behavioral users' data do not leave their devices. The SDK delivers the segment-relevant ad upon the publisher's app request.

Getting started

Publishers who wish to integrate the Audience SDK into their Android app can do so by following the steps below.

Step 1: Set Up The Environment

You will need the following prerequisites:

Step 2: Configure Your Project

  1. Open your project in Android Studio
  2. Go to app > manifests > AndroidManifest.xml and add the following after the application element:
  • Option 1: For Android:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.  ACCESS_FINE_LOCATION" />
  • Option 2: For Android Q and above:
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

<!-- UNCOMMENT THE OPTIONAL PERMISSION IF YOU WANT TO EVALUATE IF A USER IS STATIONARY
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" /> -->
  1. Request runtime permissions using this guide

Step 3: Install The SDK

  1. Go to Gradle Scripts > build.gradle (Project: {your_project}) and add the following:
allprojects {
  repositories {
    jcenter()
      google()
      maven {
      url "https://packages.weatherbug.net/groundtruth-maven"
      }
  }
}
  1. Go to Gradle Scripts > build.gradle (Module: app)
  2. Add the following to the dependencies section:
implementation 'com.groundtruth.sdk:audience:1.0.61'
  1. Add the following to the android > compileOptions section:
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
  1. Build your project

Step 4: Initialize The SDK

  1. Go to app > java > {your_project} and open the MainActivity.java file
  2. Add the following code snippet with your ACCESS_KEY and AES_PASSWORD:
@Override
  protected void onCreate(Bundle savedInstanceState) {
  new GTAudienceManager.Builder(this)
    // Your GT account's Access Key and Password 
    .with(ACCESS_KEY, AES_PASSWORD)     
    // Start the Audience SDK
    .start();
}
override fun onCreate(savedInstanceState: Bundle?) {
  // Initialize the SDK
  GTAudienceManager.Builder(this)
    // Your GT account's Access Key and Password 
    .with(ACCESS_KEY, AES_PASSWORD)
    // Start the Audience SDK  
    .start()
 }

The Audience SDK runs in the background indefinitely. If you wish to disable it, add and call the following method:

@Override
    protected void onDestroy() {
    GTAudienceManager.getInstance(this).stop();
}
override fun onDestroy() {
    GTAudienceManager.getInstance(this).stop()
}

Step 5 (Optional): Add Features

You can add the following features:

NameDescription
Get Audience DataGets the audience details
Add User InformationShares the user's birthday and gender
Enable LogsEnables the SDK's status logs

To enable those features, follow the instructions:

  1. Open the MainActivity.java file
  2. In the onCreate() function, add the following:
  • For Get Audience Data, paste the code snippet to the body method:
// Get Audience Types
GTAudienceManager.getInstance(this).getAudienceTypes(audienceTypeListener)
// Get Audience Types
GTAudienceManager.getInstance(this).getAudienceTypes(audienceTypeListener)
  • For Add User Information and Enable Logs, paste the code snippet under the GTAudienceManager.Builder(this) section:
// Add User Information
.setBirthday(1988, Month.APR, 15)
.setGender(Gender.Female) 

// Enable logs
.enableLogs()
// Add User Information
.setBirthday(1988, Month.APR, 15)
.setGender(Gender.Female)

// Enable logs
.enableLogs()

Test the integration

Get in touch with the GroundTruth team to test the SDK integration.

SDK FAQs & Troubleshooting

Have you exceeded your app's 65,536 methods limit?

Enable Multidex by following this guide to bypass this issue.

Need help finding an answer to your question?

If you have encountered any issues, contact the GroundTruth team for assistance.