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:
- Android Studio (Electric Eel)
- JDK 1.8
- Android 6.0+ (API Level 23+)
- Gradle Build Tool
- ACCESS_KEY and AES_PASSWORD provided by the GroundTruth team
- Your app must have a legitimate interest in collecting users' location data
Step 2: Configure Your Project
- Open your project in Android Studio
- 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" /> -->
- Request runtime permissions using this guide
Step 3: Install The SDK
- 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"
}
}
}
- Go to Gradle Scripts > build.gradle (Module: app)
- Add the following to the dependencies section:
implementation 'com.groundtruth.sdk:audience:1.0.61'
- Add the following to the android > compileOptions section:
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
- Build your project
Step 4: Initialize The SDK
- Go to app > java > {your_project} and open the MainActivity.java file
- 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:
Name | Description |
---|---|
Get Audience Data | Gets the audience details |
Add User Information | Shares the user's birthday and gender |
Enable Logs | Enables the SDK's status logs |
To enable those features, follow the instructions:
- Open the MainActivity.java file
- 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.
Updated over 1 year ago