Defined in package com.scandit.datacapture.core.source


Added in version 6.0.0

Possible values for the torch state.


Added in version 6.0.0

Value to indicate that the torch is turned on.


Added in version 6.0.0

Value to indicate that the torch is turned off.


Added in version 6.3.0

Value to indicate that the torch is managed automatically. The torch is turned on or off based on the available illumination.

Requires camera API 2. To make use of the automatic switch to API 2, make sure that you instantiate the camera directly with the settings instead of using Camera.applySettings().


This is an experimental feature. This functionality may or may not work for your use case or may be removed in future version of this software.

interface TorchListener

Added in version 6.3.0

Interface definition for a callback to be invoked when the TorchState of a Camera changes.

void onTorchStateChanged(TorchState state)

Added in version 6.3.0

Called when TorchState changed.

class Camera : FrameSource

Added in version 6.0.0

Gives access to the built-in camera on Android. It implements the FrameSource interface, and, as such can be set as the frame source for the DataCaptureContext.

Instances of this class are created through one of the factory methods getDefaultCamera(), or getCamera().

The camera is started by changing the desired state to FrameSourceState.ON.

By default, the resolution of captured frames as well as auto-focus and exposure settings are chosen such that they work best for a variety of use cases. To fine-tune recognition, the camera settings can be changed through applying new camera settings.

Runtime permissions

Starting from Android 6.0 (API level 23), the camera permissions can no longer be requested during app installation. Instead, permissions are requested at runtime. If your application targets API level 23 and higher, you will need to add logic to handle camera permissions before turning it on.

To achieve this, you need to check system version and if camera permission is already granted. If it’s not, you have to ask for the Manifest.permission.CAMERA permission from your Fragment or Activity. If permission has already been granted, you can enable the camera by calling desired state with FrameSourceState.ON. When the answer was negative, invoke requestPermissions and try again on onRequestPermissionsResult callback.

private void turnOnCamera() {
        && checkSelfPermission(Manifest.permission.CAMERA) != PERMISSION_GRANTED) {
            new String[]{Manifest.permission.CAMERA},
    } else {
        camera.switchToDesiredState(FrameSourceState.ON, null);

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    if (requestCode == CAMERA_PERMISSION_REQUEST
        && grantResults.length > 0
        && grantResults[0] == PERMISSION_GRANTED) {
    } else {
        // Show message about denied Camera permission.

In your application, you will most likely want to rely on the functionality implemented by the app compat library for handling the diffences between API versions. For more information on the permissions system introduced in Android 23, take a look at the Android Permission Documentation.

FrameSourceState getDesiredState()

Added in version 6.0.0

Implemented from FrameSource. See FrameSource.desiredState.

FrameSourceState getCurrentState()

Added in version 6.0.0

Implemented from FrameSource. See FrameSource.currentState.

CameraPosition getPosition()

Added in version 6.0.0

The direction that the camera faces.

void addListener(@Nullable FrameSourceListener listener)

Added in version 6.0.0

Implemented from FrameSource. See FrameSource.addListener().

void removeListener(@Nullable FrameSourceListener listener)

Added in version 6.0.0

Implemented from FrameSource. See FrameSource.removeListener().

static @Nullable Camera getDefaultCamera()

Added in version 6.0.0

Gets the default camera of the device. This method is identical to calling getCamera() repeatedly, first with CameraPosition.WORLD_FACING, then with CameraPosition.USER_FACING followed by CameraPosition.UNSPECIFIED, stopping after the first of these calls returns a non-null instance.

See getCamera() for a more detailed description of the method behavior.

static @Nullable Camera getSparkCaptureCamera()

Added in version 6.11.0

Gets the camera to be used with SparkCapture. It returns null if the device does not have a secondary world-facing camera or its camera driver does not expose it.

static @Nullable Camera getDefaultCamera(@Nullable CameraSettings settings)

Added in version 6.0.0

This method is identical to calling getDefaultCamera() and applySettings() consecutively.

static @Nullable Camera getCamera(CameraPosition position)

Added in version 6.0.0

Retrieves the camera instance of the first camera at the provided position. In case the system does not have a camera at the provided position, null is returned.

When this method is called multiple times with the same argument, the same Camera instance is returned. The FrameSource.currentState of the camera as well as the settings depend on previous invocations. For example, if the camera is currently in use and is active, the camera’s FrameSource.currentState will be FrameSourceState.ON. The only guarantee about the state and settings is that when instance is initially created, the FrameSource.currentState is FrameSourceState.OFF and has the default CameraSettings.


In case parts of your app use custom camera settings and others use the default settings, make sure to reset the camera to use the default settings when you need them by passing the default camera settings to applySettings() to ensure that you don’t have any other settings when you’d expect the defaults to be active.

The camera object is returned if present, regardless whether the application has permissions to use it or not.

The camera will use application context and the same camera object can be reused with different activities.

Starting from Android 6.0, permission to use the camera will have to be requested at runtime. This will have to be implemented in the activity itself. Consult the runtime permission documentation for details.

getCamera(position, settings)#
static @Nullable Camera getCamera(CameraPosition position,
        @NonNull CameraSettings settings)

Added in version 6.0.0

This method is identical to calling getCamera() and then applySettings() consecutively.

static @Nullable Camera fromJson(@NonNull String jsonData)

Added in version 6.0.0

Constructs a new camera with the provided JSON serialization. See Serialization for details.

switchToDesiredState(state, whenDone)#
void switchToDesiredState(FrameSourceState state, @Nullable Callback<Boolean> whenDone)

Added in version 6.0.0

Implemented from FrameSource. See FrameSource.switchToDesiredState().

void switchToDesiredState(FrameSourceState state)

Added in version 6.0.0

Convenience method for FrameSource.switchToDesiredState(): it is the same as calling switchToDesiredState() with the second argument set to null.

applySettings(settings, whenDone)#
void applySettings(@NonNull CameraSettings settings, @Nullable Runnable whenDone)

Added in version 6.0.0

Applies the camera settings to the camera. The task will complete when the settings have been applied and the camera has switched to use the new settings. If the camera is currently in FrameSourceState.OFF state, the task will complete immediately. If, on the other hand, the camera is currently in FrameSourceState.ON state, the settings will be modified on the fly.

void applySettings(@NonNull CameraSettings settings)

Added in version 6.0.0

Same as applySettings() with the second argument set to null.

boolean isTorchAvailable()

Added in version 6.0.0

Whether the torch is available for the given camera. When the camera is off, this method always returns false. When the camera is on, it returns true for cameras that support the torch, false otherwise.

TorchState getDesiredTorchState()
void setDesiredTorchState(TorchState value)

Added in version 6.0.0

The desired torch state for this camera. By default, the torch state is TorchState.OFF. When setting the desired torch state to TorchState.ON, the torch will be on as long as the camera is running (the camera’s state is FrameSourceState.ON) and off otherwise.

When setting the desired torch state for a camera that does not have a torch (see isTorchAvailable), this call has no effect.

void addTorchListener(@NonNull TorchListener listener)

Added in version 6.3.0

Add a listener that will be called when TorchState of the camera changes.

void removeTorchListener(@NonNull TorchListener listener)

Added in version 6.3.0

Remove a listener for TorchState changes.

void updateFromJson(@NonNull String jsonData)

Added in version 6.0.0

Updates the camera according to a JSON serialization. See Serialization for details.