Android SDK Integration
This is the integration document for the GroundTruth Audience SDK.
The Audience SDK generates on-device audiences based on location signals from a device on which the publisher app is installed.
Latest Release (Version 1.0.61)
Change Logs
- Added ProviderName and Segtax to SDK API
Requirements
- Android 6.0 (API Level 23)
- The App must have legitimate interest in collecting users location data
Integration
Step 1 - Obtain GT Access Key & Password
Your account manager will provide you with a unique access_key
& password
.
If you have not received them, please contact your GT account manager.
Step 2 - Adding the Audience SDK to your Project
a) Please add the following in your top-level build.gradle
file:
allprojects {
repositories {
jcenter()
google()
maven {
url "https://packages.weatherbug.net/groundtruth-maven"
}
}
}
b) Add the following line to the dependencies element in your application module’s build.gradle
.
dependencies {
implementation 'com.groundtruth.sdk:audience:1.0.61'
}
c) Add the following in your application module’s build.gradle
under android.
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...
}
d) Sync your Gradle project to ensure that the dependency is downloaded by the build system.
Step 3 - Granting Permissions
a) Required Permissions: Audience SDK is strongly dependent on the location permissions. Including them will allow the Audience SDK to initialise.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- for Android Q and above only -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
b) Optional Permissions: It is used to evaluate whether a user is stationary or not. This is not a mandatory permission; however, including it will enable SDK to work more accurately.
<!-- for Android Q and above only -->
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
To ask these runtime permissions in Android, please follow this https://developer.android.com/training/permissions/requesting
Step 4 - Initialize Audience SDK
After granting the runtime permissions, have your app initialize the Audience SDK.
Here's an example of how to initialize the Audience SDK in an Activity:
override fun onCreate(savedInstanceState: Bundle?) {
...
// Initialize the SDK
GTAudienceManager.Builder(this)
// Your account's Access Key and Password (Required)
.with(ACCESS_KEY, AES_PASSWORD)
// Start the Audience SDK (Required)
.start()
...
}
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Initialize the SDK
new GTAudienceManager.Builder(this)
// Your account's Access Key and Password (Required)
.with(ACCESS_KEY, AES_PASSWORD)
// Start the Audience SDK (Required)
.start();
...
}
You are done with the basic integration of the Audience SDK!!
Additional Options
Add User Information
The user's birthday and gender can be shared with the Audience SDK. Here's an example of how to add the user information in an Activity:
override fun onCreate(savedInstanceState: Bundle?) {
...
// Initialize the SDK
GTAudienceManager.Builder(this)
.with(ACCESS_KEY, AES_PASSWORD)
// Add user information
.setBirthday(1988, Month.APR, 15)
.setGender(Gender.Female)
.start()
...
}
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Initialize the SDK
new GTAudienceManager.Builder(this)
.with(ACCESS_KEY, AES_PASSWORD)
// Add user information
.setBirthday(1988, Month.APR, 15)
.setGender(Gender.Female)
.start();
...
}
Stop the Audience SDK
In order to stop the SDK's background service, call GTAudienceManager.getInstance(this).stop()
in the onDestroy()
function.
This is optional since Audience SDK
can run in the background indefinitely.
override fun onDestroy() {
...
GTAudienceManager.getInstance(this).stop()
...
}
@Override
protected void onDestroy() {
...
GTAudienceManager.getInstance(this).stop();
...
}
Enable Logs
This option can be used to check the Audience SDK status logs. Here's an example of how to enable logs in an Activity:
override fun onCreate(savedInstanceState: Bundle?) {
...
// Initialize the SDK
GTAudienceManager.Builder(this)
.with(ACCESS_KEY, AES_PASSWORD)
// Enable logs
.enableLogs()
.start()
...
}
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Initialize the SDK
new GTAudienceManager.Builder(this)
.with(ACCESS_KEY, AES_PASSWORD)
// Enable logs
.enableLogs()
.start();
...
}
To Get Audience Data
This option can be used to get the Audience data from SDK. Here's an example of how to get the Audience data in an Activity:
override fun onCreate(savedInstanceState: Bundle?) {
...
// Get Audience Types
GTAudienceManager.getInstance(this).getAudienceTypes(audienceTypeListener)
...
}
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Get Audience Types
GTAudienceManager.getInstance(this).getAudienceTypes(audienceTypeListener)
...
}
Troubleshooting and FAQs
Multidex
When your app and the libraries it references exceed 65,536 methods, you encounter a build error that indicates your app has reached the limit of the Android build architecture.
You can enable Multidex by following this guide: https://developer.android.com/studio/build/multidex
Updated 3 months ago