Android

The MaxMind Device SDK for Android is currently in beta.

The MaxMind Device SDK for Android collects device data and sends it to MaxMind so that the minFraud service can assign a Device ID and begin collecting fingerprint information.

Installation

Add the MaxMind Device SDK dependency to your app-level build.gradle file.

1// build.gradle.kts (Kotlin DSL)
2dependencies {
3    implementation("com.maxmind.device:device-sdk:0.2.0")
4}
1// build.gradle (Groovy DSL)
2dependencies {
3    implementation 'com.maxmind.device:device-sdk:0.2.0'
4}

Check Maven Central for the latest version.

Initialization

Initialize the SDK in your Application class. Replace MAXMIND_ACCOUNT_ID with your MaxMind account ID.

 1import android.app.Application
 2import com.maxmind.device.DeviceTracker
 3import com.maxmind.device.SdkConfig
 4
 5class MyApplication : Application() {
 6    override fun onCreate() {
 7        super.onCreate()
 8
 9        val config = SdkConfig.Builder(MAXMIND_ACCOUNT_ID).build()
10        DeviceTracker.initialize(this, config)
11    }
12}

Collect and send device data

Call collectAndSend() to collect device data and send it to MaxMind. This is a suspend function designed for use with Kotlin coroutines.

 1import android.util.Log
 2import com.maxmind.device.DeviceTracker
 3
 4lifecycleScope.launch {
 5    DeviceTracker.getInstance().collectAndSend()
 6        .onSuccess { _ ->
 7            Log.d("MaxMind", "Device data sent successfully")
 8        }
 9        .onFailure { error ->
10            Log.e("MaxMind", "Failed to send device data", error)
11        }
12}

A callback-based API is also available for Java compatibility. See the SDK documentation for details.

Explicit device linking examples

Capture the trackingToken from the collectAndSend() result and pass it to your backend for inclusion in the minFraud API request.

 1import android.util.Log
 2import com.maxmind.device.DeviceTracker
 3
 4lifecycleScope.launch {
 5    DeviceTracker.getInstance().collectAndSend()
 6        .onSuccess { trackingResult ->
 7            val token = trackingResult.trackingToken
 8            // Send the tracking token to your backend
 9            sendTokenToBackend(token)
10        }
11        .onFailure { error ->
12            Log.e("MaxMind", "Failed to send device data", error)
13        }
14}

On your backend, include the token in the minFraud API request:

1{
2  "device": {
3    "ip_address": "2001:db8::ff00:42:8329",
4    "tracking_token": "token-value-from-client"
5  }
6}

For full SDK documentation, see the device-android README.