Android SDK Integration
The minimal supported Android version is 5.0 Lollipop.
Programming language Kotlin or Java.
Before you start
Make sure you've obtained a token, server URL, and auth key from credolab
1. Add a repository
In the project build.gradle
or settings.gradle
file, add:
repositories {
..
maven {
url 'https://dl.cloudsmith.io/$TOKEN/credolab/proxyen-sdk/maven/'
}
}
repositories {
..
maven {
url = uri("https://dl.cloudsmith.io/$TOKEN/credolab/proxyen-sdk/maven/")
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
..
maven {
url "https://dl.cloudsmith.io/$TOKEN/credolab/proxyen-sdk/maven/"
}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
..
maven {
url = uri("https://dl.cloudsmith.io/$TOKEN/credolab/proxyen-sdk/maven/")
}
}
}
Note
Replace
$TOKEN
with actual token obtained from credolab
2. Declare dependencies
In the app build.gradle
or build.gradle.kts
file, add the following
dependencies {
// Required for core module
implementation 'com.google.code.gson:gson:2.8.5'
// Core module
implementation 'com.credolab:modular.core:X.Y.Z'
// Modules: each module is optional
implementation 'com.credolab:modular.account:X.Y.Z'
implementation 'com.credolab:modular.calendar:X.Y.Z'
implementation 'com.credolab:modular.contact:X.Y.Z'
implementation 'com.credolab:modular.audio:X.Y.Z'
implementation 'com.credolab:modular.images:X.Y.Z'
implementation 'com.credolab:modular.video:X.Y.Z'
implementation 'com.credolab:modular.behavioral:X.Y.Z'
// Since version `4.6.0`, the `Core` module includes functionality for collecting application metadata.
// If you are using the `Core` module version `4.6.0` or higher,
// there's no need to include the `Application` module in your app.
// implementation 'com.credolab:modular.application:X.Y.Z
// If your project is on Java
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.0' * — for Java project
// Optional: if you want to use logging module
implementation 'com.credolab:modular.logging:X.Y.Z'
implementation 'io.sentry:sentry-android:6.3.1'
}
dependencies {
// Required for core module
implementation("com.google.code.gson:gson:2.8.5")
// Core module
implementation("com.credolab:modular.core:X.Y.Z")
// Modules: each module is optional
implementation("com.credolab:modular.account:X.Y.Z")
implementation("com.credolab:modular.calendar:X.Y.Z")
implementation("com.credolab:modular.contact:X.Y.Z")
implementation("com.credolab:modular.audio:X.Y.Z")
implementation("com.credolab:modular.images:X.Y.Z")
implementation("com.credolab:modular.video:X.Y.Z")
implementation("com.credolab:modular.behavioral:X.Y.Z")
// Since version `4.6.0`, the `Core` module includes functionality for collecting application metadata.
// If you are using the `Core` module version `4.6.0` or higher,
// there's no need to include the `Application` module in your app.
// implementation("com.credolab:modular.application:X.Y.Z")
// Optional: if you want to use logging module
implementation("com.credolab:modular.logging:X.Y.Z")
implementation("io.sentry:sentry-android:6.3.1")
}
Note
Please replace
X.Y.Z
with module versions from Android page.
The final result should look like this:implementation 'com.credolab:example:4.0.0'
implementation("com.credolab:example:4.0.0")
3. Modify AndroidManifest
Click on the recipe to see what you need to add to your manifest file.
Also, whenever minSdkVersion
is lower than 21 API, please wrap SDK calls with version check:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
credoAppService = CredoAppService.Builder(applicationContext)
}
4. Build and use CredoAppService
Add this code to the onCreate
method in your MainActivity.kt
file
// When using the BehavioralModule, you can invoke the startTracking method at any point,
// even before the SDK is initialized. Call this method at the beginning of a certain user flow
BehavioralModule.startTracking()
val credoAppService = CredoAppService.Builder(applicationContext)
.addModule(AudioModule())
.addModule(BehavioralModule())
.addModule(CalendarModule())
.addModule(ContactModule())
.addModule(ImagesModule())
.addModule(RegisterAccountModule())
.addModule(VideoModule())
.addPlugin(LoggingPlugin())
.build()
// Stop the behavioral tracking to conserve resources or mark the end of a user flow
BehavioralModule.stopTracking()
// When using the BehavioralModule, you can invoke the startTracking method at any point,
// even before the SDK is initialized. Call this method at the beginning of a certain user flow
BehavioralModule.startTracking();
CredoAppService credoAppService = new CredoAppService.Builder(applicationContext)
.addModule(new AudioModule())
.addModule(new BehavioralModule())
.addModule(new CalendarModule())
.addModule(new ContactModule())
.addModule(new ImagesModule())
.addModule(new RegisterAccountModule())
.addModule(new VideoModule())
.addPlugin(new LoggingPlugin())
.build();
// Stop the behavioral tracking to conserve resources or mark the end of a user flow
BehavioralModule.stopTracking();
Additional steps for Behavioral Module
Please refer to
BehavioralModule
section for additional information about integration.
Now, you're able to use the service
val result = credoAppService.collect()
when (result) {
is CredoAppResult.Success -> Log.d(TAG, result.value)
is CredoAppResult.Error -> Log.d(TAG, "${result.message} ${result.code}")
}
CredoAppResult<String> result = credoAppService.collect();
if (result instance of CredoAppResult.Success) {
Log.d(TAG, ((CredoAppResult.Success<String>) result).getValue());
} else {
CredoAppResult.Error error = (CredoAppResult.Error) result;
String errorMessage = (error.getMessage() + " " + error.getCode());
Log.d(TAG, errorMessage);
}
Note
Remember that you always must call
collect
method on a background thread.If
collect
is successful, it will return the dataset value.
Behavioral data is cleared on
collect()
method callOnce
collect()
method is calledBehavioralModule
clears its data stored on user the device.Thus, for data consistency, our strong recommendation is to call the method only once: at the end of the user flow.
4. Upload from an Android Device (Testing purposes only)
Direct Upload Note:
In a production environment, datasets should only be uploaded via your organization's proxy server.
For testing, integration, or generating insights, you may use the following code snippet:
If you have any further questions, please do not hesitate to contact us.
Video Tutorials
Core Module Integration Tutorial
Optional Modules Integration Tutorial
Behavioral Module Integration Tutorial
Next Steps
After successfully integrating our SDK, it is recommended to proceed with the following steps to utilise our platform effectively:
- Setting up your Reverse Proxy
- Uploading your Dataset. Once the server is configured, you can upload your dataset using the server address.
- Collecting your Dataset Insight or TruValidate(formerly known as iovation) Fraud Check. With the dataset uploaded, you can now get insights or perform TruValidate Fraud Checks to assess risk based on the device and transaction details provided.
Updated 2 months ago