Scan Process - Android
The Anyline Tire Tread SDK allows for a variety of options on how to set up the scan process. In the following sections we will show the most convenient and quick way to get started with scanning.
|
You can check out our Android GitHub repository for a complete example implementation of the scan flow. |
Setup with a config object
Once the SDK has been initialized and the necessary permissions have been granted, you can start a scan.
This typed overload takes a TireTreadConfig. If you want the default behavior, pass TireTreadConfig() unchanged.
private fun startScan() {
val scanner = AnylineTireTreadScanner()
val customConfig = TireTreadConfig().apply {
// if needed, you can customize the config, e.g.:
uiConfig.measurementSystem = MeasurementSystem.Imperial
uiConfig.tapToStartScanningTooltipConfig.textOk = "Start scanning now"
scanConfig.tireWidth = 200
}
scanner.scan(
from = this,
config = customConfig,
completion = ::handleOutcome,
)
}
private fun handleOutcome(outcome: ScanOutcome) {
when (outcome) {
is CompletedOutcome -> openResultScreen(outcome.measurementUUID)
is AbortedOutcome -> finish()
is FailedOutcome -> showError(outcome.error)
}
}
When scan() returns a FailedOutcome, inspect the returned SdkError and handle it as described on the Error Handling page.
For the typed API shown above, always pass a TireTreadConfig. If you do not need any customization, use TireTreadConfig() as-is.
Setup with JSON config
You can also load the scan configuration from a JSON file and pass it through the configJson parameter.
private fun startScanFromJson() {
val scanner = AnylineTireTreadScanner()
val jsonConfig = assets.open("my_scan_config.json").bufferedReader().use { it.readText() }
scanner.scan(
from = this,
configJson = jsonConfig,
completion = ::handleOutcome,
)
}
If you already have the JSON content as a string, you can pass that string directly to configJson.
If you need a typed config object first, you can convert the same JSON with TireTreadConfig.fromJson(jsonConfig) and then pass the resulting object to scan().
|
If you want invalid JSON to surface as structured SDK errors, pass the raw string through |
Check out the next section to learn how to handle the measurement results after the scan process is finished.