java.lang.Object android.device.ScanManager
public class ScanManager
The ScanManager class provides developers access to barcode reader in the device.
To decode barcodes with this class, according to the following steps,
openScanner
to power on the barcode reader.
getOutputMode
and set the output mode using switchOutputMode
.
getTriggerMode
and set the trigger mode using setTriggerMode
.
getParameterInts
or set the scanner configuration properties PropertyID
using
setParameterInts
.
startDecode
.
If the configured PropertyID.WEDGE_KEYBOARD_ENABLE
is 0, your registered broadcast receiver will be called when a successful decode occurs.
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);
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);
}
}
}
};
stopDecode
to end the decode session.
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 |
public static final java.lang.String ACTION_DECODE
public static final java.lang.String BARCODE_STRING_TAG
public static final java.lang.String BARCODE_TYPE_TAG
public static final java.lang.String BARCODE_LENGTH_TAG
public static final java.lang.String DECODE_DATA_TAG
public ScanManager()
public boolean openScanner()
ScanManager mScanManager = new ScanManager();
boolean ret = mScanManager.openScanner();
if(ret) {
//open successful
}
public boolean closeScanner()
mScanManager.openScanner();
boolean ret = mScanManager.closeScanner();
if(ret) {
//close successful
}
public boolean switchOutputMode(int mode)
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.
mScanManager.openScanner();
int mode = 0;
boolean ret = mScanManager.switchOutputMode(mode);
if(ret) {
//switch Output Successful
}
public int getOutputMode()
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
}
public boolean getScannerState()
ScanManager mScanManager = new ScanManager();
boolean ret = mScanManager.getScannerState();
if(ret) {
//scanner power on
} else {
//scanner power off
}
public boolean stopDecode()
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
}
public boolean startDecode()
mScanManager.openScanner();
boolean ret = mScanManager.startDecode();
if(ret) {
//scanner start decoding
}
public boolean lockTrigger()
mScanManager.openScanner();
boolean ret = mScanManager.lockTrigger();
if(ret) {
//disable the scan button successful
}
public boolean unlockTrigger()
mScanManager.lockTrigger();
boolean ret = mScanManager.unlockTrigger();
if(ret) {
//enable the scan button successful
}
public boolean getTriggerLockState()
mScanManager.openScanner();
boolean ret = mScanManager.getTriggerLockState();
if(ret) {
//scanner trigger is already active
}
public boolean resetScannerParameters()
mScanManager.openScanner();
boolean ret = mScanManager.resetScannerParameters();
if(ret) {
//Reset to factory default settings for all barcode symbology types successful
}
public void setTriggerMode(Triggering mode)
mode
- These are the different operational modes you choose first when setting up your trigger mode. The default is HOST mode.
import android.device.scanner.configuration.Triggering;
mScanManager.openScanner();
Triggering mode = Triggering.HOST; //Set the HOST mode
mScanManager.setTriggerMode(mode);
public Triggering getTriggerMode()
Triggering
for possible values.
import android.device.scanner.configuration.Triggering;
mScanManager.openScanner();
Triggering mode = mScanManager.getTriggerMode();
//The return value could be Triggering.HOST, Triggering.CONTINUOUS, or Triggering.PULSE.
public int setParameterInts(int[] idBuffer, int[] valueBuffer)
idBuffer
- The indexes to the parameters to be set. See PropertyID
.
valueBuffer
- The values to be set.
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
}
public int[] getParameterInts(int[] idBuffer)
idBuffer
- The indexes to the programming parameteres. See PropertyID
.
mScanManager.openScanner();
int[] index = new int[]{ PropertyID.WEDGE_KEYBOARD_ENABLE };
int[] value = mScanManager.getParameterInts(index);
//value of PropertyID.WEDGE_KEYBOARD_ENABLE
public boolean setParameterString(int[] idBuffer, java.lang.String[] valueBuffer)
idBuffer
- to the parameter that is to be set. See PropertyID
.
valueBuffer
- The string used to set the parameter.
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
}
public java.lang.String[] getParameterString(int[] idBuffer)
idBuffer
- The indexes to the programming parameteres. See PropertyID
.
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
public boolean isSymbologySupported(Symbology barcodeType)
barcodeType
- Barcode type is one of the Symbology.
import android.device.scanner.configuration.Symbology
public boolean isQRSupported(ScanManager decoder) {
return decoder.isSymbologySupported(Symbology.QRCODE);
}
public boolean isSymbologyEnabled(Symbology barcodeType)
barcodeType
- This get the current enable setting for a particular data
type(one of the barcode typein the Symbology class).
import android.device.scanner.configuration.Symbology
public boolean isCode128Enabled(ScanManager decoder) {
return decoder.isSymbologyEnabled(Symbology.CODE128);
}
public void enableAllSymbologies(boolean enable)
enable
- Specifies whether or not the symbologies will be enabled. If
false, the symbologies are disabled, otherwise they are enabled.
public void enableAll(ScanManager decoder) {
decoder.enableAllSymbologies(true);
}
public void enableSymbology(Symbology barcodeType, boolean enable)
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.
import android.device.scanner.configuration.Symbology
public void enableCode128(ScanManager decoder) {
decoder.enableSymbology(Symbology.CODE128, true);
}