android-device-catalog-parser

Kotlin CI with Gradle Validate JSON Schemas

android-device-catalog-parser

Android Device catalog CSV parser that is available from Google Play developer console.

Usage

Follow jitpack guideline for latest instructions.

// Step 1. Add the JitPack repository to your build file
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}


// Step 2. Add the dependency
dependencies {
    implementation 'com.github.hossain-khan:android-device-catalog-parser:1.10'
}

Basic Usage

The library provides a simple way to parse Android Device Catalog CSV files: ```kotlin import dev.hossain.android.catalogparser.Parser import dev.hossain.android.catalogparser.models.AndroidDevice // Parser is now an object (no instantiation needed) val csvContent = // Your CSV content as String // Simple parsing - returns only successfully parsed devices val devices: List<AndroidDevice> = Parser.parseDeviceCatalogData(csvContent) println("Successfully parsed ${devices.size} devices") ```

Enhanced Usage with Statistics

For more insights into the parsing process, including information about discarded records: ```kotlin import dev.hossain.android.catalogparser.Parser import dev.hossain.android.catalogparser.models.ParseResult val csvContent = // Your CSV content as String // Enhanced parsing - returns detailed statistics val result: ParseResult = Parser.parseDeviceCatalogDataWithStats(csvContent) println("Parsing Summary:") println(" Total rows processed: ${result.totalRows}") println(" Successfully parsed: ${result.successfulCount}") println(" Discarded: ${result.discardedCount}") println(" Success rate: ${"%.2f".format(result.successRate)}%") // Access the successfully parsed devices val devices = result.devices // Analyze discard reasons if (result.discardReasons.isNotEmpty()) { println("\nDiscard reasons:") result.discardReasons.forEach { (reason, count) -> println(" $reason: $count") } } ``` #### Example Output When parsing a CSV with mixed valid and invalid data: ``` Parsing Summary: Total rows processed: 1000 Successfully parsed: 892 Discarded: 108 Success rate: 89.20% Discard reasons: Missing required field: Brand: 45 Missing required field: GPU: 32 Unknown form factor: Desktop: 18 Missing required field: RAM (TotalMem): 13 ```

Advanced Configuration

Configure parser behavior for missing data and unknown values: ```kotlin import dev.hossain.android.catalogparser.Parser import dev.hossain.android.catalogparser.ParserConfig import dev.hossain.android.catalogparser.models.FormFactor val csvContent = // Your CSV content as String // Configure parser to use defaults instead of discarding rows val config = ParserConfig.builder() .useDefaultsForMissingFields(true) .defaultStringValue("Unknown") // Use "Unknown" for missing string fields .defaultIntValue(0) // Use 0 for missing integer fields .defaultFormFactor(FormFactor.PHONE) // Use PHONE for unknown form factors .build() // Parse with configuration val devices = Parser.parseDeviceCatalogData(csvContent, config) val result = Parser.parseDeviceCatalogDataWithStats(csvContent, config) println("With defaults: ${result.successfulCount} devices parsed (${result.successRate}% success)") ``` #### Configuration Options | Option | Default | Description | |-------------------------------|---------|---------------------------------------------------------------------------------------------| | `useDefaultsForMissingFields` | `false` | Use default values instead of discarding rows with missing required fields | | `defaultStringValue` | `""` | Default value for missing string fields (e.g., "Unknown", "N/A") | | `defaultIntValue` | `0` | Default value for missing integer fields | | `defaultFormFactor` | `null` | Default form factor for unknown values. If `null`, unknown form factors are still discarded | #### Before vs After Configuration ```kotlin // Default behavior (backward compatible) val defaultResult = Parser.parseDeviceCatalogDataWithStats(csvContent) // Result: 22,751 devices parsed (93.50% success rate) // With configuration to include all data val configResult = Parser.parseDeviceCatalogDataWithStats(csvContent, config) // Result: 24,332 devices parsed (100% success rate) ```

CSV Snapshot

Java/Kotlin output

The CSV is parsed into a list of AndroidDevice class.

Here is a snapshot of parsed CSV file

Snapshot Files

Device catalog can always be downloaded from the Google Play Console

The latest catalog data is available in the catalog-data/ directory with metadata:

The catalog-metadata.json file provides information about the catalog including export date, total records, and URLs to all catalog variations.

🌎 Sample App

Take a look at https://android-device.gohk.xyz/ web app that loads device catalog and allows you to browse then and see some valiable stats πŸ“Š

You can also take a look into google-play Android Device Universe app on the Google Playβ„’

πŸ“– Updating Data Snapshot

The update catalog to latest snapshot, ⬇️ download CSV and overwrite android-devices-catalog.csv located in sample/src/main/resources. Once done, run Update Catalog workflow πŸͺ„