Scan Process - Android
The AnylineTireTreadSDK
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 TireTreadScanView. |
Setup with a config object
-
Compose
-
Xml + ViewBinding
@Composable
private fun Content() {
// You can pass the tire width as an integer,
// or let the Default UI request this value from the user
// by not png this parameter to the TireTreadScanView
val tireWidth = 200
// The config parameter is optional, and can safely be ignored if no modifications are required.
TireTreadScanView(
config = TireTreadConfig(),
/* if needed, you can customize the config, e.g.: */
// .apply {
// uiConfig.apply {
// measurementSystem = MeasurementSystem.Imperial
// tapToStartScanningTooltipConfig.apply {
// textOk = "Start scanning now"
// }
// }
// scanConfig.apply {
// this.tireWidth = tireWidth
// }
// },
onScanAborted = ::onScanAborted,
onScanProcessCompleted = ::onScanProcessCompleted,
callback = null,
// Optionally, you can listen to all the scan events to build custom workflows
//callback = ::handleEvent,
onError = { measurementUUID, exception ->
// handle possible errors during scanning
finish()
})
}
private fun onScanAborted(measurementUUID: String?) {
// handle scan aborted, e.g. leave the screen
}
private fun onScanProcessCompleted(measurementUUID: String) {
// handle scan process completed, e.g. show a results page
}
// This is an advanced use-case, and generally not necessary when using the Default UI.
// private fun handleEvent(event: ScanEvent) {
// when(event) {
// is OnScanStart -> {
// // handle onScanStart event
// }
// // handle other events
// is ...
// else -> {
// // handle previously unhandled events
// }
// }
// }
override fun onCreate(savedInstanceState: Bundle?) {
binding.tireTreadScanView.apply {
// You can pass the tire width as an integer,
// or let the Default UI request this value from the user
// by not passing this parameter to the TireTreadScanView
val tireWidth = 200
// The tireTreadConfig parameter is optional, and can safely be ignored if no modifications are required.
init(tireTreadConfig = TireTreadConfig(),
/* if needed, you can customize the config, e.g.: */
// .apply {
// uiConfig.apply {
// measurementSystem = MeasurementSystem.Imperial
// tapToStartScanningTooltipConfig.apply {
// textOk = "Start scanning now"
// }
// }
// scanConfig.apply {
// this.tireWidth = tireWidth
// }
// },
onScanAborted = ::onScanAborted,
onScanProcessCompleted = ::onScanProcessCompleted,
callback = null,
// Optionally, you can listen to all the scan events to build custom workflows
//callback = ::handleEvent,
) { measurementUUID, exception ->
// handle possible errors during scanning
finish()
}
setViewCompositionStrategy(
ViewCompositionStrategy.DisposeOnLifecycleDestroyed(
this@ScanActivity
)
)
}
}
private fun onScanAborted(measurementUUID: String?) {
// handle scan aborted
}
private fun onScanProcessCompleted(measurementUUID: String) {
// handle scan process completed
}
// This is an advanced use-case, and generally not necessary when using the Default UI.
// private fun handleEvent(event: ScanEvent) {
// when(event) {
// is OnScanStart -> {
// // handle onScanStart event
// }
// // handle other events
// is ...
// else -> {
// // handle previously unhandled events
// }
// }
// }
Setup with JSON config
Another way to configure the TireTreadScanView
is via a JSON config.
You can provide the name of a .json
file located in your application’s asset folder, or even the full JSON string as an input.
@Composable
private fun Content() {
TireTreadScanView(
tireTreadScanViewConfig = "my_scan_config.json", //you can also use the full JSON string as an input!
onScanAborted = ::onScanAborted,
onScanProcessCompleted = ::onScanProcessCompleted,
// Optionally, you can listen to all the scan events to build custom workflows
// callback = ::handleEvent
) { measurementUUID, exception ->
// handle possible errors
}
}
private fun onScanAborted(measurementUUID: String?) {
// handle scan aborted
}
private fun onScanProcessCompleted(measurementUUID: String) {
// handle scan process completed
}
// This is an advanced use-case, and generally not necessary when using the Default UI.
// private fun handleEvent(event: ScanEvent) {
// when(event) {
// is OnScanStart -> {
// // handle onScanStart event
// }
// // handle other events
// is ...
// else -> {
// // handle previously unhandled events
// }
// }
// }
You can check out our GitHub example repository for an implementation of the Scan Activity. |
Check out the next section to learn how to handle the measurement results after the scan process is finished.