Result API for the Android Barcode Scanner
Starting with SDK version 8.0.0, a new generic class, Result<T>, has been introduced.
This class is returned by most API methods, including scanner creation sdkInstance.create<NAME>Scanner() and scanner execution using scannerName.run(imageRef). Consequently, most SDK calls now return this unified result type.
On successful execution, the API returns Result.Success, which contains the expected result object.
If an error occurs—such as a license issue or an internal exception—the API returns Result.Failure. This is a sealed class (similar to Result) and can be mapped to a specific error type from the list below:
sealed class Failure(message: String) : Result<Nothing>, Throwable(message)
class UnknownError(message: String) : Failure(message)
class InvalidLicenseError(message: String = "License requirements are not satisfied.") : Failure(message)
class NullPointerError(message: String) : Failure(message)
class InvalidArgumentError(message: String) : Failure(message)
class InvalidImageRefError(message: String) : Failure(message)
class ComponentUnavailableError(message: String) : Failure(message)
class IllegalStateError(message: String) : Failure(message)
class IoError(message: String) : Failure(message)
class InvalidDataError(message: String) : Failure(message)
class OperationCanceledError(message: String) : Failure(message)
class OutOfMemoryError(message: String) : Failure(message)
class TimeoutError(message: String) : Failure(message)
What does this mean in practice? It means you can now handle results in the way that best fits your project. The Result class also provides several extension functions that enhance its core functionality.
The result can be handled using a when expression, similar to handling other sealed classes.
loading...
It is also possible to retrieve the result object directly; if the operation fails, null is returned or an exception is thrown.
loading...
For Kotlin users who prefer chaining operations, several additional utility methods are available.
loading...
Results from multiple scanners can be chained together, with all exceptions along the chain handled appropriately.
loading...
loading...
For Java users, the only option is to use if statements with type casting to access the result.
loading...
loading...
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get free trial licenseScanbot SDK is part of the Apryse SDK product family
A mobile scan is just the start. With Apryse SDKs, you can expand mobile workflows into full cross‑platform document processing. Whether you need to edit PDFs, add secure digital signatures, or use a fast, customizable document viewer and editor, Apryse gives you the tools to build powerful features quickly.
Learn more
