public class BarCodeReader
extends java.lang.Object
To decode bar codes with this class, use the following steps:
open(int)
.
getParameters()
.
BarCodeReader.Parameters
object and call
setParameters(BarCodeReader.Parameters)
.
setDecodeCallback(BarCodeReader.DecodeCallback)
to register a
bar code decode event handler.
SurfaceHolder
to
setPreviewDisplay(SurfaceHolder)
.
startDecode()
or startHandsFreeDecode(int)
.
Your registered DecodeCallback will be called when a successful decode occurs or if
the configured timeout expires.
stopDecode()
to end the decode session.
release()
to release the BarCodeReader for
use by other applications. Applications should release the BarCodeReader
immediately in android.app.Activity#onPause()
(and re-open()
it in android.app.Activity#onResume()
).
This class is not thread-safe, and is meant for use from one event thread.
Callbacks will be invoked on the event thread open(int)
was called from.
This class's methods must never be called from multiple threads at once.
Modifier and Type | Class and Description |
---|---|
static interface |
BarCodeReader.AutoFocusCallback
Callback interface used to notify on completion of reader auto focus.
|
static interface |
BarCodeReader.DecodeCallback
Callback interface used to deliver decode results.
|
static interface |
BarCodeReader.ErrorCallback
Callback interface for reader error notification.
|
static interface |
BarCodeReader.OnZoomChangeListener
Callback interface for zoom changes during a smooth zoom operation.
|
class |
BarCodeReader.Parameters
BarCodeReader service settings.
|
static class |
BarCodeReader.ParamNum
Parameter numbers
|
static class |
BarCodeReader.ParamVal |
static interface |
BarCodeReader.PictureCallback
Callback interface used to supply image data from a photo capture.
|
static interface |
BarCodeReader.PreviewCallback
Callback interface used to deliver copies of preview frames as
they are displayed.
|
static class |
BarCodeReader.PropertyNum
Property numbers used to get information from the scanner hardware.
|
static class |
BarCodeReader.ReaderInfo
Information about a bar code reader
|
class |
BarCodeReader.Size
Image size (width and height dimensions).
|
static interface |
BarCodeReader.VideoCallback
Callback interface used to supply image data in video capture mode.
|
Modifier and Type | Field and Description |
---|---|
static int |
BCR_ERROR
Function failed
|
static int |
BCR_SUCCESS
Function completed successfully
|
static int |
BCRDR_ERROR_SERVER_DIED
Media server died.
|
static int |
BCRDR_ERROR_UNKNOWN
Unspecified reader error.
|
static int |
BCRDR_EVENT_MOTION_DETECTED
Motion detected event ID
|
static int |
BCRDR_EVENT_SCAN_MODE_CHANGED
Scan mode changed event ID
|
static int |
BCRDR_EVENT_SCANNER_RESET
Scanner reset event ID
|
static int |
DECODE_STATUS_CANCELED
onDecodeComplete length value indicating that the decode was canceled
|
static int |
DECODE_STATUS_ERROR
onDecodeComplete length value indicating that an error occurred
|
static int |
DECODE_STATUS_MULTI_DEC_COUNT
onDecodeComplete length value indicating a multi-decode event
|
static int |
DECODE_STATUS_TIMEOUT
onDecodeComplete length value indicating that the decode timed out
|
Modifier and Type | Method and Description |
---|---|
void |
addCallbackBuffer(byte[] callbackBuffer)
Adds a pre-allocated buffer to the preview callback buffer queue.
|
void |
autoFocus(BarCodeReader.AutoFocusCallback cb)
Starts reader auto-focus and registers a callback function to run when the
reader is focused.
|
void |
cancelAutoFocus()
Cancels any auto-focus function in progress.
|
void |
disableAllCodeTypes()
Disables all code types
|
void |
enableAllCodeTypes()
Enables all code types
|
int |
FWUpdate(java.lang.String FilePath,
boolean forceDownload,
boolean IgnoreSignature)
Update the scanner Firmware.
|
int |
getDecodeCount()
Returns the number of barcodes decoded during a multiple barcode
decode session.
|
byte[] |
getLastDecImage()
Get the last decoded image.
|
static int |
getNumberOfReaders()
Returns the number of physical readers available on this device.
|
int |
getNumParameter(int paramNum)
Returns the value of a specified bar code reader numeric parameter or BCR_ERROR
if the specified parameter number is invalid.
|
int |
getNumProperty(int propNum)
Returns the value of a specified bar code reader numeric property or BCR_ERROR
if the specified property number is invalid.
|
BarCodeReader.Parameters |
getParameters()
Returns the current settings for this BarCodeReader service.
|
static void |
getReaderInfo(int readerId,
BarCodeReader.ReaderInfo readerInfo)
Returns the information about a particular reader.
|
java.lang.String |
getStrParameter(int paramNum)
Returns the value of a specified bar code reader string parameter or BCR_ERROR
if the specified parameter number is invalid.
|
java.lang.String |
getStrProperty(int propNum)
Returns the value of a specified bar code reader string property or null
if the specified property number is invalid.
|
void |
lock()
Re-locks the reader to prevent other processes from accessing it.
|
static BarCodeReader |
open()
Creates a new BarCodeReader object to access the first back-facing reader on
the device.
|
static BarCodeReader |
open(Context context)
Creates a new BarCodeReader object to access the first back-facing reader on
the device.
|
static BarCodeReader |
open(int readerId)
Creates a new BarCodeReader object to access a particular hardware reader.
|
static BarCodeReader |
open(int readerId,
Context context)
Creates a new BarCodeReader object to access a particular hardware reader.
|
boolean |
previewEnabled()
Return current preview state.
|
void |
reconnect()
Reconnects to the reader service after another process used it.
|
void |
release()
Disconnects and releases the BarCodeReader object resources.
|
void |
setAutoFocusDelay(int initialDelay,
int secondaryDelay)
Specifies whether or not automatic auto-focus should be performed
during decode operations and if so, how many frames to initially
wait before issuing the the first auto-focus request and how many
frames to wait after receiving an auto-focus complete notification
before issuing another request.
|
void |
setDecodeCallback(BarCodeReader.DecodeCallback cb)
Installs callbacks to be invoked when a decode request completes
or a decoder event occurs.
|
void |
setDefaultParameters()
Sets all bar code reader parameters to their default values.
|
void |
setDisplayOrientation(int degrees)
Set the clockwise rotation of preview display in degrees.
|
void |
setErrorCallback(BarCodeReader.ErrorCallback cb)
Registers a callback to be invoked when an error occurs.
|
void |
setOneShotPreviewCallback(BarCodeReader.PreviewCallback cb)
Installs a callback to be invoked for the next preview frame in addition
to displaying it on the screen.
|
int |
setParameter(int paramNum,
int paramVal)
Sets the value of a specified bar code reader numeric parameter.
|
int |
setParameter(int paramNum,
java.lang.String paramVal)
Sets the value of a specified bar code reader string parameter.
|
void |
setParameters(BarCodeReader.Parameters params)
Changes the settings for this BarCodeReader service.
|
void |
setPreviewCallbackWithBuffer(BarCodeReader.PreviewCallback cb)
Installs a callback to be invoked for every preview frame, using buffers
supplied with
addCallbackBuffer(byte[]) , in addition to
displaying them on the screen. |
void |
setPreviewDisplay(SurfaceHolder holder)
Sets the
Surface to be used for live preview. |
void |
setZoomChangeListener(BarCodeReader.OnZoomChangeListener listener)
Registers a listener to be notified when the zoom value is updated by the
reader driver during smooth zoom.
|
int |
startDecode()
Starts capturing frames and passes the captured frames to the decoder.
|
int |
startHandsFreeDecode(int mode)
Starts capturing frames and passes the captured frames to the decoder.
|
void |
startPreview()
Starts capturing frames in preview mode.
|
void |
startSmoothZoom(int value)
Zooms to the requested value smoothly.
|
void |
startVideoCapture(BarCodeReader.VideoCallback cb)
Starts capturing frames in video mode.
|
void |
startViewFinder(BarCodeReader.VideoCallback cb)
Starts capturing frames in view finder mode in preparation of taking a snapshot.
|
void |
stopDecode()
Stops capturing and decoding frames.
|
void |
stopPreview()
Stops capturing and drawing preview frames to the surface, and
resets the reader for a future call to
startPreview() . |
void |
stopSmoothZoom()
Stops the smooth zoom.
|
void |
takePicture(BarCodeReader.PictureCallback cb)
Triggers an asynchronous image capture.
|
void |
unlock()
Unlocks the reader to allow another process to access it.
|
public static final int BCR_SUCCESS
public static final int BCR_ERROR
public static final int DECODE_STATUS_TIMEOUT
public static final int DECODE_STATUS_CANCELED
public static final int DECODE_STATUS_ERROR
public static final int DECODE_STATUS_MULTI_DEC_COUNT
public static final int BCRDR_EVENT_SCAN_MODE_CHANGED
public static final int BCRDR_EVENT_MOTION_DETECTED
public static final int BCRDR_EVENT_SCANNER_RESET
public static final int BCRDR_ERROR_UNKNOWN
public static final int BCRDR_ERROR_SERVER_DIED
public static int getNumberOfReaders()
public static void getReaderInfo(int readerId, BarCodeReader.ReaderInfo readerInfo)
getNumberOfReaders()
returns N, the valid id is 0 to N-1.public final void lock()
unlock()
is
called. Normally reconnect()
is used instead.
If you are not recording video, you probably do not need this method.
java.lang.RuntimeException
- if the reader cannot be re-locked (for
example, if the reader is still in use by another process).public final void unlock()
release()
is called. To allow rapid handoff
between processes, you can call this method to release the reader
temporarily for another process to use; once the other process is done
you can call reconnect()
to reclaim the reader.
This must be done before calling
android.media.MediaRecorder#setCamera(BarCodeReader)
.
If you are not recording video, you probably do not need this method.
java.lang.RuntimeException
- if the reader cannot be unlocked.public final void reconnect() throws java.io.IOException
unlock()
is called, another process may use the
reader; when the process is done, you must reconnect to the reader,
which will re-acquire the lock and allow you to continue using the
reader.
This must be done after android.media.MediaRecorder
is
done recording if android.media.MediaRecorder#setReader(BarCodeReader)
was used.
If you are not recording video, you probably do not need this method.
java.io.IOException
- if a connection cannot be re-established (for
example, if the reader is still in use by another process).public final int getNumProperty(int propNum)
public final java.lang.String getStrProperty(int propNum)
public final int getNumParameter(int paramNum)
public final java.lang.String getStrParameter(int paramNum)
public final int setParameter(int paramNum, int paramVal)
public final int setParameter(int paramNum, java.lang.String paramVal)
paramNum
- The parameter number to setparamVal
- The new value for the parameterpublic final void setDefaultParameters()
public final void addCallbackBuffer(byte[] callbackBuffer)
The size of the buffer is determined by multiplying the preview
image width, height, and bytes per pixel. The width and height can be
read from BarCodeReader.Parameters.getPreviewSize()
. Bytes per pixel
can be computed from
android.graphics.ImageFormat#getBitsPerPixel(int)
/ 8,
using the image format from BarCodeReader.Parameters.getPreviewFormat()
.
This method is only necessary when
setPreviewCallbackWithBuffer(PreviewCallback)
is used. When
setOneShotPreviewCallback(PreviewCallback)
is used, buffers
are automatically allocated.
callbackBuffer
- the buffer to add to the queue.
The size should be width * height * bits_per_pixel / 8.setPreviewCallbackWithBuffer(PreviewCallback)
public final int FWUpdate(java.lang.String FilePath, boolean forceDownload, boolean IgnoreSignature)
FilePath
- - Full path with the filenameforceDownload
- - whether to force download or not - recommended trueIgnoreSignature
- - whether to ignore signature - recommended falsepublic final void startVideoCapture(BarCodeReader.VideoCallback cb)
setPreviewDisplay(SurfaceHolder)
, the frames will
be drawn to the surface.
BarCodeReader.VideoCallback#onVideoFrame(format, width, height, byte[], BarCodeReader)
will be called when preview data becomes available. The data passed will be
in the format and resolution specified by ParamNum.IMG_FILE_FORMAT and
ParamNum.IMG_VIDEOSUB.
public final void startViewFinder(BarCodeReader.VideoCallback cb)
setPreviewDisplay(SurfaceHolder)
,
the frames will be drawn to the surface.public final void startPreview()
setPreviewDisplay(SurfaceHolder)
, the frames will
be drawn to the surface.
If setOneShotPreviewCallback(BarCodeReader.PreviewCallback)
or
setPreviewCallbackWithBuffer(BarCodeReader.PreviewCallback)
was
called, BarCodeReader.PreviewCallback.onPreviewFrame(byte[], BarCodeReader)
will be called when preview data becomes available.
public final void stopPreview()
startPreview()
.public final int startDecode()
setPreviewDisplay(SurfaceHolder)
,
the frames will be drawn to the surface. When a decode occurs or timeout
expires and setDecodeCallback(BarCodeReader.DecodeCallback)
was called,
#BarCodeReader.DecodeCallback.onDecodeComplete(int, int, byte[], BarCodeReader)
will be called with the decode results.public final int startHandsFreeDecode(int mode)
setPreviewDisplay(SurfaceHolder)
,
the frames will be drawn to the surface. If motion is detected, a motion event
is generated. If a decode occurs a decode event is generated. Decoding
continues until stopDecode()
is called.mode
- Indicates the trigger mode to use. It must be either
#ParamVal.HANDSFREE
or #ParamVal.AUTO_AIM
.public final void stopDecode()
public final boolean previewEnabled()
public final void startSmoothZoom(int value)
BarCodeReader.OnZoomChangeListener
of the zoom value and whether zoom is stopped at
the time. For example, suppose the current zoom is 0 and startSmoothZoom
is called with value 3. The
BarCodeReader.OnZoomChangeListener.onZoomChange(int, boolean, BarCodeReader)
method will be called three times with zoom values 1, 2, and 3.
Applications can call stopSmoothZoom()
to stop the zoom earlier.
Applications should not call startSmoothZoom again or change the zoom
value before zoom stops. If the supplied zoom value equals to the current
zoom value, no zoom callback will be generated. This method is supported
if BarCodeReader.Parameters.isSmoothZoomSupported()
returns true.value
- zoom value. The valid range is 0 to BarCodeReader.Parameters.getMaxZoom()
.java.lang.IllegalArgumentException
- if the zoom value is invalid.java.lang.RuntimeException
- if the method fails.setZoomChangeListener(OnZoomChangeListener)
public final void stopSmoothZoom()
BarCodeReader.OnZoomChangeListener
to know when the zoom is actually stopped. This
method is supported if BarCodeReader.Parameters.isSmoothZoomSupported()
is true.java.lang.RuntimeException
- if the method fails.public final void setDisplayOrientation(int degrees)
This does not affect the order of byte array passed in BarCodeReader.PreviewCallback.onPreviewFrame(byte[], com.zebra.adc.decoder.BarCodeReader)
, JPEG pictures, or recorded videos. This
method is not allowed to be called during preview.
If you want to make the reader image show in the same orientation as the display, you can use the following code.
#import com.zebra.adc.decoder; public static void setReaderDisplayOrientation(Activity activity, int readerId, BarCodeReader reader) { int result; int degrees = 0; int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); BarCodeReader.ReaderInfo info = new BarCodeReader.ReaderInfo(); BarCodeReader.getReaderInfo(readerId, info); switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; default: break; } if ( info.facing == BarCodeReader.ReaderInfo.BCRDR_FACING_FRONT ) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } reader.setDisplayOrientation(result); }
degrees
- the angle that the picture will be rotated clockwise.
Valid values are 0, 90, 180, and 270. The starting
position is 0 (landscape).setPreviewDisplay(SurfaceHolder)
public final int getDecodeCount()
public final void enableAllCodeTypes()
public final void disableAllCodeTypes()
public final byte[] getLastDecImage()
public static BarCodeReader open(int readerId)
You must call release()
when you are done using the reader,
otherwise it will remain locked and be unavailable to other applications.
Your application should only have one BarCodeReader object active at a time for a particular hardware reader.
Callbacks from other methods are delivered to the event loop of the thread which called open(). If this thread has no event loop, then callbacks are delivered to the main application event loop. If there is no main application event loop, callbacks are not delivered.
Caution: On some devices, this method may
take a long time to complete. It is best to call this method from a
worker thread (possibly using android.os.AsyncTask
) to avoid
blocking the main application UI thread.
readerId
- the hardware reader to access, between 0 and getNumberOfReaders()
-1.java.lang.RuntimeException
- if connection to the reader service fails (for
example, if the reader is in use by another process).public static BarCodeReader open()
open(int)
public static BarCodeReader open(int readerId, Context context)
You must call release()
when you are done using the reader,
otherwise it will remain locked and be unavailable to other applications.
Your application should only have one BarCodeReader object active at a time for a particular hardware reader.
Callbacks from other methods are delivered to the event loop of the thread which called open(). If this thread has no event loop, then callbacks are delivered to the main application event loop. If there is no main application event loop, callbacks are not delivered.
Caution: On some devices, this method may
take a long time to complete. It is best to call this method from a
worker thread (possibly using android.os.AsyncTask
) to avoid
blocking the main application UI thread.
readerId
- the hardware reader to access, between 0 and getNumberOfReaders()
-1.context
- is the application contextjava.lang.RuntimeException
- if connection to the reader service fails (for
example, if the reader is in use by another process).public static BarCodeReader open(Context context)
open(int)
public final void release()
You must call this as soon as you're done with the BarCodeReader object.
public final void setPreviewDisplay(SurfaceHolder holder) throws java.io.IOException
Surface
to be used for live preview.
A surface is necessary for preview, and preview is necessary to take
pictures. The same surface can be re-set without harm.
The SurfaceHolder
must already contain a surface when this
method is called. If you are using android.view.SurfaceView
,
you will need to register a SurfaceHolder.Callback
with
SurfaceHolder#addCallback(SurfaceHolder.Callback)
and wait for
SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)
before
calling setPreviewDisplay() or starting preview.
This method must be called before startPreview()
. The
one exception is that if the preview surface is not set (or set to null)
before startPreview() is called, then this method may be called once
with a non-null parameter to set the preview surface. (This allows
reader setup and surface creation to happen in parallel, saving time.)
The preview surface may not otherwise change while preview is running.
holder
- containing the Surface on which to place the preview,
or null to remove the preview surfacejava.io.IOException
- if the method fails (for example, if the surface
is unavailable or unsuitable).public final void autoFocus(BarCodeReader.AutoFocusCallback cb)
Callers should check
BarCodeReader.Parameters.getFocusMode()
to determine if
this method should be called. If the reader does not support auto-focus,
it is a no-op and BarCodeReader.AutoFocusCallback.onAutoFocus(boolean, BarCodeReader)
callback will be called immediately.
If your application should not be installed on devices without auto-focus, you must declare that your application uses auto-focus with the <uses-feature> manifest element.
If the current flash mode is not
BarCodeReader.Parameters.FLASH_MODE_OFF
, flash may be
fired during auto-focus, depending on the driver and reader hardware.
cb
- the callback to runcancelAutoFocus()
public final void cancelAutoFocus()
public final void setAutoFocusDelay(int initialDelay, int secondaryDelay)
#Parameters.setFocusMode(String)
and setParameters(Parameters)
to set the focus mode to #BarCodeReader.Parameters.FOCUS_MODE_AUTO
.
When this function is used to enable automatic auto-focus requests,
auto-focus callbacks are disabled. If an application needs to receive
auto-focus callbacks, it should issue its own autoFocus(AutoFocusCallback)
requests and should not call this function.initialDelay
- the number of frames to process when a decode
session is started before issuing the first auto-focus request.
If this parameter is less than one and secondaryDelay is greater
than zero, an auto-focus request will be issued as soon as the
decode session is started. If both initialDelay and secondaryDelay
are both less than one, no auto-focus requests will be issued.secondaryDelay
- the number of frames to process after
receiving an auto-focus complete notification before issuing
another auto-focus request. If this parameter is less than one,
only the initial auto-focus request, if any, will be performed.public final void setDecodeCallback(BarCodeReader.DecodeCallback cb)
cb
- a callback object that receives a notification of a completed,
decode request or null to stop receiving decode callbacks.public final void takePicture(BarCodeReader.PictureCallback cb)
This method is only valid when the decoder is idle or view finder
mode is active (after calling #startViewFinder()
). Image capture
will be stopped after the picture taken callback is called. Callers must
call #startViewFiner()
and/or takePicture() again if they want to
re-start the view finder or take more pictures.
After calling this method, you must not call startPreview()
,
#startViewFinder()
or take another picture until the picture taken
callback has returned.
cb
- the callback for processed image datapublic final void setOneShotPreviewCallback(BarCodeReader.PreviewCallback cb)
cb
- a callback object that receives a copy of the next preview frame,
or null to stop receiving callbacks.public final void setPreviewCallbackWithBuffer(BarCodeReader.PreviewCallback cb)
addCallbackBuffer(byte[])
, in addition to
displaying them on the screen. The callback will be repeatedly called
for as long as preview is active and buffers are available.
Any other preview callbacks are overridden.
The purpose of this method is to improve preview efficiency and frame
rate by allowing preview frame memory reuse. You must call
addCallbackBuffer(byte[])
at some point -- before or after
calling this method -- or no callbacks will received.
The buffer queue will be cleared if this method is called with a null callback
or if setOneShotPreviewCallback(BarCodeReader.PreviewCallback)
is called.
cb
- a callback object that receives a copy of the preview frame,
or null to stop receiving callbacks and clear the buffer queue.addCallbackBuffer(byte[])
public final void setZoomChangeListener(BarCodeReader.OnZoomChangeListener listener)
listener
- the listener to notifystartSmoothZoom(int)
public final void setErrorCallback(BarCodeReader.ErrorCallback cb)
cb
- The callback to runpublic void setParameters(BarCodeReader.Parameters params)
params
- the Parameters to use for this BarCodeReader servicejava.lang.RuntimeException
- if any parameter is invalid or not supported.getParameters()
public BarCodeReader.Parameters getParameters()
setParameters(BarCodeReader.Parameters)
to take effect.