Skip to main content

Result API for the Android Document Scanner SDK

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 via ScanbotSDK(context).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.Unexpected. 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.

Handle Result with when/switch
loading...

It is also possible to retrieve the result object directly; if the operation fails, null is returned or an exception is thrown.

Handle Result with getter functions
loading...

For Kotlin users who prefer chaining operations, several additional utility methods are available.

Handle Result with chain API
loading...

Results from multiple scanners can be chained together, with all exceptions along the chain handled appropriately.

Chain Result with SDK calls
loading...
Combine Result of SDK calls
loading...

For Java users, the only option is to use if statements with type casting to access the result.

Handle Result with if statements in Java
loading...
Handle Result with getter functions in Java
loading...

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get free trial license