Skip to content

maxmind/device-android

Repository files navigation

MaxMind Device SDK for Android

Android SDK for collecting and reporting device data to MaxMind.

Requirements

  • Android API 29+ (Android 10+)
  • Kotlin 1.9.22+
  • AndroidX libraries

Installation

Gradle (Kotlin DSL)

Add the dependency to your app's build.gradle.kts:

dependencies {
    implementation("com.maxmind.device:device-sdk:0.1.0")
}

Gradle (Groovy)

dependencies {
    implementation 'com.maxmind.device:device-sdk:0.1.0'
}

Quick Start

1. Initialize the SDK

Initialize the SDK in your Application class or main activity:

import com.maxmind.device.DeviceTracker
import com.maxmind.device.config.SdkConfig

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        val config = SdkConfig.Builder(123456)  // Your MaxMind account ID
            .enableLogging(BuildConfig.DEBUG)
            .build()

        DeviceTracker.initialize(this, config)
    }
}

2. Collect and Send Device Data

Using Kotlin Coroutines

lifecycleScope.launch {
    DeviceTracker.getInstance().collectAndSend()
        .onSuccess {
            Log.d("SDK", "Data sent successfully")
        }
        .onFailure { error ->
            Log.e("SDK", "Failed to send data", error)
        }
}

Using Callbacks (Java-compatible)

DeviceTracker.getInstance().collectAndSend { result ->
    result.onSuccess {
        Log.d("SDK", "Data sent successfully")
    }.onFailure { error ->
        Log.e("SDK", "Failed to send data", error)
    }
}

Java Example

DeviceTracker.getInstance().collectAndSend(result -> {
    if (result.isSuccess()) {
        Log.d("SDK", "Data sent successfully");
    } else {
        Throwable error = result.exceptionOrNull();
        Log.e("SDK", "Failed to send data", error);
    }
});

3. Manual Data Collection

Collect device data without sending:

val deviceData = DeviceTracker.getInstance().collectDeviceData()
println("Device: ${deviceData.build.manufacturer} ${deviceData.build.model}")

Configuration Options

SdkConfig.Builder

val config = SdkConfig.Builder(123456)              // Your MaxMind account ID
    .serverUrl("https://custom-server.com/api")  // Optional: Custom server URL
    .enableLogging(true)                          // Optional: Enable debug logging
    .collectionInterval(60_000)                   // Optional: Auto-collect every 60 seconds
    .build()
Builder Method Type Default Description
Builder(accountID) Int required Your MaxMind account ID
.serverUrl(url) String Default servers Custom server URL
.enableLogging(enabled) Boolean false Enable debug logging
.collectionInterval(ms) Long 0 Auto-collection interval in milliseconds (0 = disabled)

Permissions

The SDK requires the following permissions (automatically included):

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

ProGuard / R8

The SDK includes consumer ProGuard rules. No additional configuration is needed.

Sample App

See the sample module for a complete working example demonstrating:

  • SDK initialization
  • Device data collection
  • Data transmission
  • Error handling

To run the sample app:

./gradlew :sample:installDebug

Building the SDK

Build Library

./gradlew :device-sdk:assemble

Run Tests

./gradlew :device-sdk:test

Generate Documentation

./gradlew :device-sdk:dokkaHtml

Documentation will be generated in device-sdk/build/dokka/.

Contributing

  1. Fork the repository
  2. Set up your development environment (see SETUP.md)
  3. Create a feature branch
  4. Make your changes
  5. Run tests and code quality checks
  6. Submit a pull request

License

This software is Copyright (c) 2025 by MaxMind, Inc.

This is free software, licensed under the Apache License, Version 2.0 or the MIT License, at your option. Copyright 2025 MaxMind, Inc.

Support

For support, please visit maxmind.com/en/company/contact-us.

If you find a bug or have a feature request, please open an issue on GitHub.

About

MaxMind Device SDK for Android

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •