A common need for the developers that develop apps for Datalogic Mobile Computers is to enable/disable the Scan Engine in order, for example, to avoid accidental readings with the scanner in input field where it is not allowed.
The components responsible for reading barcode are substantially 3: Triggers, Wedges (Keyboard, Intent, Web…) and Listeners.
Trigger: are software or physical buttons to press to actually activate the scan engine. In code they are controlled through the Trigger interface that represents the trigger, see API reference here.
Listeners: they are components that you can declare in an application. These components are waiting to receive the code read by the Scan Engine, see API reference here.
Wedges: it is like an implementation of automatic Listener, outside the application, that forwards the read code for example (in the case of the Keyboard wedge) to the currently focused input field in the application, see API reference here.
The minimum condition in order to activate the scanner is that
- At least one trigger is enabled (and pressed)
- At least one listener is active, in listening for new codes.
If one of these two conditions is not verified, the Scan Engine won’t turn on.
So, according to the application architecture you can use a combination of these to enable/disable the Scan Engine.
Method 1 (register/release all decode listeners):
So, for example, if you disable the Keyboard Wedge and the Listeners declared in your application, the Scan Engine will be disabled despite all the triggers are still Active
Datalogic Android Studio SDK provides configuration.keyboardWedge.enable.set() to enable/disable Keyboard Wedge, see API reference here
import com.datalogic.decode.configuration.ScannerProperties; ... ScannerProperties configuration = ScannerProperties.edit(manager); ... //disable configuration.keyboardWedge.enable.set(false); //store them int errorCode = configuration.store(manager, true); // Check return value. if(errorCode != ConfigException.SUCCESS) { //do somethingin in case of failure }
It provides also methods to remove/add Listeners, see API reference here :
import com.datalogic.decode.BarcodeManager; ... BarcodeManager barcode = new BarcodeManager(); ... //release all listners registered barcode.release(); //register listner // barcode.addReadListener(this)
Method 2 (enable/disable all triggers):
Another way to disable the Scan Engine is to disable the Triggers.
Datalogic Android Studio SDK provides the Trigger.setEnabled() method, see API reference here.
import com.datalogic.device.input.KeyboardManager; import com.datalogic.device.input.Trigger; ...... KeyboardManager keyManager = new KeyboardManager(); for (Trigger trigger : keyManager.getAvailableTriggers()) { boolean result = trigger.setEnabled(false); if(result){ //operation done }else{ //do something in case of failure } }
At this link there is the a simple test app .apk that proves it, the app was tested on the Memor10.
Donato Cataldo
L3 - Mobile Products Specialist SW Engineer