Skip to main content

Testing real-time scanning with a mock camera

Overview

The SDK's mock camera feature lets developers emulate a real camera's behavior using an image file in place of a live camera stream. You can set the path to the image file within the app folder or another specified directory.

caution

On Android, the mock camera currently requires a one-time manual approval for accessing files. This might change in the future.

Initialization

To initialize the mock camera, run the following code before initializing the RTU UI screen or before injecting the camera into the UI.

Mock Camera Initialization
loading...
caution

The mock camera feature is only intended for testing purposes. Please do not use it in production.

Limitations

The mock camera works with all RTU UI screens. When using the Classic UI, it only works with BarcodeScannerView and DocumentScannerView.

If you want to use other scanners with the Classic UI camera, you need to manually replace ScanbotCameraXView with ScanbotMockCameraView. ScanbotCameraXView itself does not contain mock functionalities.

Tips

MockCameraResourceProvider.getFrameImagePath() is called for each detection frame. This means you can change the detection frame for one camera session as many times as you need. For example, you could start with a blurry image and improve the quality over time.

Permissions

The mock camera feature currently does not need permission if you are using internal files. For working with files outside the app directory (e.g., for accessing files from common locations like the Downloads folder, which is useful for testing with a variety of preloaded images) you need to add app permissions to the AndroidManifest.xml. For Android < 30 use android.permission.READ_EXTERNAL_STORAGE permission and for Android >= 30 use android:name="android.permission.MANAGE_EXTERNAL_STORAGE".

You can also enable this permission via adb:

adb shell pm grant com.test.appname android.permission.READ_EXTERNAL_STORAGE
adb shell appops set com.test.appname MANAGE_EXTERNAL_STORAGE allow

We're currently investigating whether having to grant this permission can be avoided.

Want to scan longer than one minute?

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

Get free trial license