ScanManager

##
android.device
Class ScanManager

    java.lang.Object
      android.device.ScanManager

    public class ScanManager

extends java.lang.Object

The ScanManager class provides developers access to barcode reader in the device.

To decode barcodes with this class, according to the following steps,

1. Obtain an instance of BarCodeReader with ScanManager scan = new ScanManager().
2. Call `openScanner` to power on the barcode reader.
3. After that, the default output mode is TextBox Mode that send barcode data to the focused text box. User can check the output mode using `getOutputMode` and set the output mode using `switchOutputMode`.
4. Then, the default trigger mode is manually trigger signal. User can check the trigger mode using `getTriggerMode` and set the trigger mode using `setTriggerMode`.
5. If necessary, check the current settings using `getParameterInts` or set the scanner configuration properties `PropertyID` using `setParameterInts`.
6. To begin a decode session, call `startDecode`. If the configured `PropertyID.WEDGE_KEYBOARD_ENABLE` is 0, your registered broadcast receiver will be called when a successful decode occurs.
7. If the output mode is intent mode, the captured data is sent as an implicit Intent. An application interestes in the scan data should register an action as android.intent.ACTION_DECODE_DATA broadcast listerner. To get a barcode data, see the example below. `
   byte[] barcode = arg1.getByteArrayExtra(DECODE_DATA_TAG);
   String barcodeString = arg1.getStringExtra(BARCODE_STRING_TAG);
   int barcodeLen = arg1.getIntExtra(BARCODE_LENGTH_TAG,0);
   byte type = arg1.getByteExtra(BARCODE_TYPE_TAG,(byte)0);`
8. To get a still image through an Android intent. After receiving the scan result, send "action.scanner_capture_image" broadcast, and then obtain the picture by registering "scanner_capture_image_result" broadcast receiver. To get a bitmap, see the example below. `
   private BroadcastReceiver mReceiver = new BroadcastReceiver() {
   @Override
   public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   if ("scanner_capture_image_result".equals(action)) {
   byte[] imageData = intent.getByteArrayExtra("bitmapBytes");
   if(imageData!=null && imageData.length > 0) {
   Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
   if(bitmap != null) {
   //Success to get a bitmap
   } else {
   //Failed to get a bitmap
   }
   } else {
   Log.i("onReceive , ignore imageData:" + imageData);
   }
   }
   }
   };`
9. Call `stopDecode` to end the decode session.
10. Call `closeScanner` to power off the barcode reader.

For more information about the Scanner, read ScanManager sample.

Field Summary
`static java.lang.String` | `ACTION_DECODE` Action sent as a broadcast Intent by the ScanManager when a successful decode occurs.
`static java.lang.String` | `BARCODE_LENGTH_TAG` Constant Value: "length"
`static java.lang.String` | `BARCODE_STRING_TAG` Constant Value: "barcode_string"
`static java.lang.String` | `BARCODE_TYPE_TAG` Constant Value: "barcodeType"
`static java.lang.String` | `DECODE_DATA_TAG` Constant Value: "barcode"

Constructor Summary
`ScanManager()` The scanmanager class provides access to related barcode readers in the device.

Method Summary
`boolean` | `closeScanner()` Turn off the power for the barcode reader.
`void` | `enableAllSymbologies(boolean enable)` Enable or disable all supported symbologies.
`void` | `enableSymbology(Symbology barcodeType, boolean enable)` Enable or disable a barcode symbology type.
`int` | `getOutputMode()` Get the current scan result output mode.
`int[]` | `getParameterInts(int[] idBuffer)` Get all values of given scanner configuration properties.
`java.lang.String[]` | `getParameterString(int[] idBuffer)` Get all strings of given scanner configuration properties.
`boolean` | `getScannerState()` Get the scanner power states.
`boolean` | `getTriggerLockState()` Get the scan trigger status.
`Triggering` | `getTriggerMode()` Get the current trigger mode.
`boolean` | `isSymbologyEnabled(Symbology barcodeType)` Get current enable setting for a particular barcode symbology.
`boolean` | `isSymbologySupported(Symbology barcodeType)` Judge whether the device decoder can read specific barcode symbology.
`boolean` | `lockTrigger()` Set the scan trigger inactive (disable the scan button).
`boolean` | `openScanner()` Turn on the power for the barcode reader.
`boolean` | `resetScannerParameters()` Reset to factory default settings for all barcode symbology types.
`int` | `setParameterInts(int[] idBuffer, int[] valueBuffer)` Set all values of given scanner configuration properties.
`boolean` | `setParameterString(int[] idBuffer, java.lang.String[] valueBuffer)` Set all strings of given scanner configuration properties.
`void` | `setTriggerMode(Triggering mode)` Set a operational mode to control decode.
`boolean` | `startDecode()` Call this method to start decoding.
`boolean` | `stopDecode()` This stops any data acquisition currently in progress.
`boolean` | `switchOutputMode(int mode)` Set the output mode of the barcode reader (either send output to text box or as Android intent).
`boolean` | `unlockTrigger()` Set the scan trigger active (enable the scan button).

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

FIELD DETAIL

### ACTION_DECODE

    public static final java.lang.String ACTION_DECODE

  Action sent as a broadcast Intent by the ScanManager when a successful decode occurs.
  See Also:
    Constant Field Values

### BARCODE_STRING_TAG

    public static final java.lang.String BARCODE_STRING_TAG

  Tag set to obtain barcode string.
  See Also:
    Constant Field Values

### BARCODE_TYPE_TAG

    public static final java.lang.String BARCODE_TYPE_TAG

  Tag set to obtain the label type of the barcode.

  See Also:
    Constant Field Values

### BARCODE_LENGTH_TAG

    public static final java.lang.String BARCODE_LENGTH_TAG

  Tag set to obtain the label length of the barcode.

  See Also:
    Constant Field Values

### DECODE_DATA_TAG

    public static final java.lang.String DECODE_DATA_TAG

  Tag set to obtain the output data as a byte array. In the case of concatenated barcodes, the decode data is concatenated and sent out as a single array.

  See Also:
    Constant Field Values

Constructor Detail

### ScanManager

    public ScanManager()

Method Detail

### openScanner

    public boolean openScanner()

  Turn on the power for the barcode reader.

  Parameters:
    none
  Returns:
    True if successful, false if failed.
  Example:
    `ScanManager mScanManager = new ScanManager();
    boolean ret = mScanManager.openScanner();
    if(ret) {
    //open successful
    }`

### closeScanner

    public boolean closeScanner()

  Turn off the power for the barcode reader.

  Parameters:
    none
  Returns:
    True if successful, false if failed.
  Example:
    `mScanManager.openScanner();
    boolean ret = mScanManager.closeScanner();
    if(ret) {
    //close successful
    }`

### switchOutputMode

    public boolean switchOutputMode(int mode)

  Set the output mode of the barcode reader (either send output to text box or as Android intent). TextBox Mode allows the captured data to be sent to the text box in focus. Intent mode allows the captured data to be sent as an implicit Intent. Application interested in the scan data should register an action as ACTION_DECODE broadcast listerner. In the onReceive method, get the information. The information are barcode data, bardcode string, length of barcode data, and barcode type (symbology).

  Parameters:
    `mode` - 0 if barcode output is to be sent as intent, 1 if barcode output is to be sent to the text box in focus. The default output mode is TextBox Mode.
  Returns:
    True if successful, false if failed.
  Example:
    `mScanManager.openScanner();
    int mode = 0;
    boolean ret = mScanManager.switchOutputMode(mode);
    if(ret) {
    //switch Output Successful
    }`

### getOutputMode

    public int getOutputMode()

  get the current scan result output mode.

  Parameters:
    none
  Returns:
    0 if the barcode is sent as intent, 1 if barcode is sent to the text box in focus. Default 1.
  Example:
    `mScanManager.openScanner();
    int mode = mScanManager.getOutputMode();
    if(mode == 0) {
    //barcode is sent as intent
    } else if(mode == 1){
    //barcode is sent to the text box in focus
    }`

### getScannerState

    public boolean getScannerState()

  Get the scanner power states.

  Parameters:
    none
  Returns:
    True if the scanner power on, false if power off.
  Example:
    `ScanManager mScanManager = new ScanManager();
    boolean ret = mScanManager.getScannerState();
    if(ret) {
    //scanner power on
    } else {
    //scanner power off
    }`

### stopDecode

    public boolean stopDecode()

  This stops any data acquisition currently in progress.

  Parameters:
    none
  Returns:
    True if successful, false if failed.
  Example:
    `mScanManager.startDecode();
    //After calling startDecode, stopDecode is called before timeout to stop scanning
    boolean ret = mScanManager.stopDecode();
    if(ret) {
    //scanner stop decode successful
    } else {
    //scanner stop decode failed
    }`

### startDecode

    public boolean startDecode()

  Call this method to start decoding.

  Parameters:
    none
  Returns:
    True if successful, false if failed.
  Example:
    `mScanManager.openScanner();
    boolean ret = mScanManager.startDecode();
    if(ret) {
    //scanner start decoding
    }`

### lockTrigger

    public boolean lockTrigger()

  Set the scan trigger inactive (disable the scan button).

  Parameters:
    none
  Returns:
    True if successful, false if failed.
  Example:
    `mScanManager.openScanner();
    boolean ret = mScanManager.lockTrigger();
    if(ret) {
    //disable the scan button successful
    }`

### unlockTrigger

    public boolean unlockTrigger()

  Set the scan trigger active (enable the scan button).

  Parameters:
    none
  Returns:
    True if successful, false if failed.
  Example:
    `mScanManager.lockTrigger();
    boolean ret = mScanManager.unlockTrigger();
    if(ret) {
    //enable the scan button successful
    }`

### getTriggerLockState

    public boolean getTriggerLockState()

  Get the scan trigger status.

  Parameters:
    none
  Returns:
    True if the scan trigger is already active.
  Example:
    `mScanManager.openScanner();
    boolean ret = mScanManager.getTriggerLockState();
    if(ret) {
    //scanner trigger is already active
    }`

### resetScannerParameters

    public boolean resetScannerParameters()

  Reset to factory default settings for all barcode symbology types.

  Parameters:
    none
  Returns:
    True if successful, false if failed.
  Example:
    `mScanManager.openScanner();
    boolean ret = mScanManager.resetScannerParameters();
    if(ret) {
    //Reset to factory default settings for all barcode symbology types successful
    }`

### setTriggerMode

    public void setTriggerMode(Triggering mode)

  Set a operational mode to control decode.

  Parameters:
    `mode` - These are the different operational modes you choose first when setting up your trigger mode. The default is HOST mode.
    PULSE : a trigger will activate the scan engine, and start decoding. It will be deactivated when a valid code is found, or when the trigger is released, or when the time out is reached.
    CONTINUOUS : a trigger pull activates the laser and decode processing. The laser remains on and decode processing continues until a valid decode or the laser on time out is reached.
    HOST : a host command issues the triggering signal. The scan engine interprets an actual trigger pull as a Level triggering option.
  Returns:
    none
  Example:
    `import android.device.scanner.configuration.Triggering;
    mScanManager.openScanner();
    Triggering mode = Triggering.HOST; //Set the HOST mode
    mScanManager.setTriggerMode(mode);`

### getTriggerMode

    public Triggering getTriggerMode()

  Get the current trigger mode.

  Parameters:
    none
  Returns:
    the current trigger mode. See `Triggering` for possible values.
  Example:
    `import android.device.scanner.configuration.Triggering;
    mScanManager.openScanner();
    Triggering mode = mScanManager.getTriggerMode();
    //The return value could be Triggering.HOST, Triggering.CONTINUOUS, or Triggering.PULSE.`

### setParameterInts

    public int setParameterInts(int[] idBuffer,
                                int[] valueBuffer)

  Set all values of given scanner configuration properties.

  Parameters:
    `idBuffer` - The indexes to the parameters to be set. See `PropertyID`.
    `valueBuffer` - The values to be set.
  Returns:
    0 if successful, -1 if failed.
  Example:
    `mScanManager.openScanner();
    int[] index = new int[]{ PropertyID.WEDGE_KEYBOARD_ENABLE, PropertyID.WEDGE_KEYBOARD_TYPE, PropertyID.GOOD_READ_BEEP_ENABLE};
    int[] value = new int[]{1, 1, 1};
    int ret = mScanManager.setParameterInts(index, value);
    if(ret == 0) {
    //set success
    }`

### getParameterInts

    public int[] getParameterInts(int[] idBuffer)

  Get all values of given scanner configuration properties.

  Parameters:
    `idBuffer` - The indexes to the programming parameteres. See `PropertyID`.
  Returns:
    Int arrary of the parameters.
  Example:
    `mScanManager.openScanner();
    int[] index = new int[]{ PropertyID.WEDGE_KEYBOARD_ENABLE };
    int[] value = mScanManager.getParameterInts(index);
    //value of PropertyID.WEDGE_KEYBOARD_ENABLE`

### setParameterString

    public boolean setParameterString(int[] idBuffer,
                                      java.lang.String[] valueBuffer)

  Set all strings of given scanner configuration properties.

  Parameters:
    `idBuffer` - to the parameter that is to be set. See `PropertyID`.
    `valueBuffer` - The string used to set the parameter.
  Returns:
    False if the index or value is error, and otherwise true.
  Example:
    `import android.device.scanner.configuration.PropertyID;
    mScanManager.openScanner();
    int[] key = new int[]{ PropertyID.WEDGE_INTENT_ACTION_NAME };
    String[] action = { "udroid.test.action" };
    boolean ret = mScanManager.setParameterString(key, action);
    if(ret) {
    //update successful
    } else {
    //index or value is error
    }`

### getParameterString

    public java.lang.String[] getParameterString(int[] idBuffer)

  Get all strings of given scanner configuration properties.

  Parameters:
    `idBuffer` - The indexes to the programming parameteres. See `PropertyID`.
  Returns:
    String arrary of the parameters.
  Example:
    `import android.device.scanner.configuration.PropertyID;
    mScanManager.openScanner();
    int[] index = new int[]{ PropertyID.WEDGE_INTENT_ACTION_NAME, PropertyID.WEDGE_INTENT_DATA_STRING_TAG };
    String[] value = mScanManager.getParameterString(index);
    //value is string arrary of the parameters`
    ``

### isSymbologySupported

    public boolean isSymbologySupported(Symbology barcodeType)

  Judge whether the device decoder can read specific barcode symbology.

  Parameters:
    `barcodeType` - Barcode type is one of the Symbology.
  Returns:
    False if the decoder is not able to read the particular barcode type, and otherwise true.
  Example:
    `import android.device.scanner.configuration.Symbology
    public boolean isQRSupported(ScanManager decoder) {
    return decoder.isSymbologySupported(Symbology.QRCODE);
    }`

### isSymbologyEnabled

    public boolean isSymbologyEnabled(Symbology barcodeType)

  Get current enable setting for a particular barcode symbology.

  Parameters:
    `barcodeType` - This get the current enable setting for a particular data type(one of the barcode typein the Symbology class).
  Returns:
    False if the particular data type is disabled, and otherwise true.
  Example:
    `import android.device.scanner.configuration.Symbology
    public boolean isCode128Enabled(ScanManager decoder) {
    return decoder.isSymbologyEnabled(Symbology.CODE128);
    }`

### enableAllSymbologies

    public void enableAllSymbologies(boolean enable)

  Enable or disable all supported symbologies.

  Parameters:
    `enable` - Specifies whether or not the symbologies will be enabled. If false, the symbologies are disabled, otherwise they are enabled.
  Returns:
    none
  Note:When the decoding configuration changes due a call to this method, the Scanner engine must be in the power on state.
  Example:
    `public void enableAll(ScanManager decoder) {
    decoder.enableAllSymbologies(true);
    }`

### enableSymbology

    public void enableSymbology(Symbology barcodeType,
                                boolean enable)

  Enable or disable a barcode symbology type.

  Parameters:
    `barcodeType` - Indicates the type of data whose enable setting is to be altered. See Symbology.
    `enable` - Specifies whether or not the data type will be enabled. Set to true to enable.
  Returns:
    none
  Note: When the decoding configuration changes due a call to this method, the Scanner engine must be in the power on state.
  Example:
    `import android.device.scanner.configuration.Symbology
    public void enableCode128(ScanManager decoder) {
    decoder.enableSymbology(Symbology.CODE128, true);
    }`