4.4. The Scanner activity

The simplest way to start using enioka Scan in an activity is simply to inherit from the ScannerCompatActivity class. This class implements the ScannerClient interface and handles the scanner service bindings and life cycle. It also exposes a default UI to print scan results, status messages and some buttons to manually control the scanner device from the app.

Most of its methods are protected and can be overridden if needed. Mainly, methods from the ScannerClient interface should be replaced with your own to adapt the way scan results are handled by your application.

By default, the activity will use the default search options to initiate scanner search. There are two ways to change these options: override the getServiceInitExtras() method, and passing the search options as extras to the intent starting the activity. In case both are used, the method is applied first, then intent extras.

This page will describe attributes and methods specific to this activity, disregarding overrides. For most users, it is recommended to only change the value of attributes or interface methods, as overriding class methods may cause unexpected side-effects. For example, using a custom layout only requires changing the corresponding layout ID attributes.

4.4.1. ScannerCompatActivity attributes

boolean laserModeOnly = false

If true, the activity will not switch to using the camera, even if no other scanners are available.

boolean enableScan = true

If false, the activity will behave like a standard AppCompatActivity.

boolean goToCamera = false

If true, the activity will directly switch to using the camera. This boolean is automatically set to true if the scanner service finds no scanner after the first search.

boolean useBluetooth = true

If true, the activity will check that the application has bluetooth permissions before starting the service. This does not affect scanner search options.

int layoutIdLaser = R.layout.activity_main

The layout used by the activity when using regular scanner devices. May be replaced with your own.

Integer layoutIdCamera = null

The layout used by the activity when using the camera as a scanner. May be replaced with your own. If the camera SDK is included, it will be defined to :::{cpp:var}R.layout.activity_main_alt

Integer cameraViewId = null

If the camera SDK is included, it will be set to :::{cpp:var}R.id.camera_scan_view It is the ID of the CameraBarcodeScanView inside the layoutIdCamera layout.

int cameraToggleId = R.id.scanner_bt_camera

The ID of the optional ImageButton on which to press to manually switch to camera mode.

int flashlightViewId = R.id.scanner_flashlight

The ID of the optional ImageButton on which to press to toggle the flashlight/illumination.

Integer scannerModeToggleViewId = null

If the camera SDK is included, it will be set to :::{cpp:var}R.id.scanner_switch_zxing. It is the ID of the optional ImageButton on which to press to toggle the zxing/zbar camera scan library.

Integer scannerModeTogglePauseId =

The ID of the optional toggle button on which to press to pause/unpause the scanner. If the camera SDK is included and it is not overwrite, it will be set by default to

int keyboardOpenViewId = R.id.scanner_bt_keyboard

The ID of the optional toggle button on which to display the manual input fragment.

ManualInputFragment manualInputFragment;

An optional fragment allowing to input a value with the soft keyboard (for cases when scanners do not work).

List<ManualInputItem> autocompletionItems = new ArrayList<>()

Auto completion items for manual input (with manualInputFragment).

int threshold = 5

How many characters should be entered before auto-completion starts.

ScannerServiceApi scannerService;

The instance of the bound scanner service, can be used to access service methods but should not be replaced.

Initialized by the onStart() and onResume() methods.

CameraScanner cameraScannerProvider = null;

The optional instance of the camera scanner provider, is set if the camera SDK is included. Can be used to access some methods of CameraBarcodeScanViewScanner. Should not be replaced.

CameraBarcodeScanViewScanner is a simple provider-less implementation of the Scanner interface.

Initialized by the initCamera() method.

4.4.2. ScannerCompatActivity methods

getServiceInitExtras() Bundle
Returns:

The search options that will be used when starting the service. These options may be overriden by intent extras when launching the activity.

setAutocompletion(List<String> autocompletion, int threshold) void

Inserts the given autocompletion strings into the autocompletionItems and updates the autocompletion threshold.

Parameters:
  • autocompletion (List<String>) – The autocompletion items to add.

  • threshold (int) – The new threshold.

setAutocompletionItems(List<ManualInputItem> items, int threshold) void

Replaces autocompletionItems with the given list and updates the autocompletion threshold.

Parameters:
  • autocompletion (List<String>) – The autocompletion items to use.

  • threshold (int) – The new threshold.

initCamera() void

Switches the activity to camera mode. After this method is called, goToCamera is set to true.

anyScannerSupportsIllumination() boolean

Checks whether any available scanner supports Illumination.

anyScannerHasIlluminationOn() boolean

Checks whether any available scanner has Illumination toggled on.

See also