|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.amms.control.camera.ImageScanner
net.rim.device.api.barcodelib.BarcodeScanner
public final class BarcodeScanner
An ImageScanner
intended for barcode scanning. See com.google.zxing
for the detection and decoding libraries.
You are notified of the decoded text by the BarcodeDecoderListener
when a barcode is detected by the zxing library.
Alternatively, you can use ImageDecoderListener
which will give you access to all the decoded information via Result
.
Typical usage for scanning QR barcodes:
BarcodeDecoderListener listener = new BarcodeDecoderListener() { public void barcodeDecoded( String rawText ) { // called when a barcode has been detected. Process the rawText here. // stopScan has been automatically called. } };
Hashtable hints = new Hashtable(); Vector formats = new Vector(); formats.addElement(BarcodeFormat.QR_CODE); hints.put(DecodeHintType.POSSIBLE_FORMATS, formats); BarcodeDecoder decoder = new BarcodeDecoder(hints);
MainScreen screen = new MainScreen(); BarcodeScanner scanner = new BarcodeScanner( decoder, listener ); screen.add( scanner.getViewfinder() ); UiApplication.getUiApplication().pushScreen( screen ); scanner.startScan();
You might try hints.put(DecoderHintType.TRY_HARDER, Boolean.TRUE)
as well for a more thorough detection,
especially when decoding 1D barcodes. However, decoding time for each frame will significantly increase.
When attempting to scan 1D barcodes, barcodes are read left to right. Thus, orientation of the barcode in the viewfinder matters, and should be aligned to be read left to right.
Constructor Summary | ||
---|---|---|
BarcodeScanner(BarcodeDecoder decoder,
ImageDecoderListener listener)
Creates a new instance of BarcodeScanner . |
||
BarcodeScanner(BarcodeDecoder decoder,
BarcodeDecoderListener listener)
Creates a new instance of BarcodeScanner . |
Method Summary | ||
---|---|---|
Player |
getPlayer()
Retrieves the camera player. |
|
Field |
getVanillaViewfinder()
Retrieves a non-augmented viewfinder for the player returned by BarcodeScanner.getPlayer() . |
|
VideoControl |
getVideoControl()
Retrieves the VideoControl for the player returned by
BarcodeScanner.getPlayer() . |
|
Field |
getViewfinder()
Retrieves the viewfinder for the player returned by BarcodeScanner.getPlayer() . |
|
void |
setBarcodeDecoder(BarcodeDecoder decoder)
Sets the BarcodeDecoder . |
|
void |
startScan()
Starts scanning for a barcode. |
|
void |
stopScan()
Stops scanning for a barcode. |
Methods inherited from class net.rim.device.api.amms.control.camera.ImageScanner |
---|
getDecoder, isColorIncluded, isScanning, setDecoder, setHint |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BarcodeScanner(BarcodeDecoder decoder, BarcodeDecoderListener listener) throws IOException, MediaException
BarcodeScanner
.
This class sets a hint setHint
with ImageScannerHint.BARCODE_SCANNING
.
decoder
- BarcodeDecoder
that can be configured to detect barcodes.listener
- BarcodeDecoderListener
to be notified when a barcode has been detected.
IllegalArgumentException
- if decoder or listener is null
.
SecurityException
- if the caller does not have security permission to create the Player
.
MediaException
- if Manager.createPlayer(java.lang.String)
specifies capture://video?encoding=image/jpeg
as its encoding.
IOException
- if there was a problem connecting with the source.public BarcodeScanner(BarcodeDecoder decoder, ImageDecoderListener listener) throws IOException, MediaException
BarcodeScanner
.
When used in conjunction with the zxing library, your ImageDecoderListener
will get notified
via ImageDecoderListener.imageDecoded(Object)
with an object of type Result
.
This class sets a hint setHint
with ImageScannerHint.BARCODE_SCANNING
.
decoder
- BarcodeDecoder
that can be configured to detect barcodes.listener
- BarcodeDecoderListener
to be notified when a barcode has been detected.
IllegalArgumentException
- if decoder or listener is null
SecurityException
- if the caller does not have security permission to create the Player
.
MediaException
- if Manager.createPlayer(java.lang.String)
specifies capture://video?encoding=image/jpeg
as its encoding.
IOException
- if there was a problem connecting with the source pointed to by the Locator
.Method Detail |
---|
public Player getPlayer()
getPlayer
in class ImageScanner
public VideoControl getVideoControl()
VideoControl
for the player returned by
BarcodeScanner.getPlayer()
.
getVideoControl
in class ImageScanner
VideoControl
associated with this BarcodeScanner
.public Field getViewfinder()
BarcodeScanner.getPlayer()
.
This viewfinder is a ViewfinderOverlay
. If getDecoder
returns an instance of BarcodeDecoder
at the time this method is called, the ViewfinderOverlay
will also contain a single BarcodeScannerOverlayField
.
getViewfinder
in class ImageScanner
ViewfinderOverlay
.public final Field getVanillaViewfinder()
BarcodeScanner.getPlayer()
.
ImageScanner.getViewfinder()
public void startScan() throws MediaException
startScan
in class ImageScanner
MediaException
- if the Player
cannot be started or scanning cannot be started.
IllegalStateException
- if no BarcodeDecoder
has been set, or if the Player
is in the CLOSED state.
SecurityException
- if the caller does not have security permission to start the Player
.public void stopScan() throws MediaException
stopScan
in class ImageScanner
MediaException
- if the Player
cannot be stopped or scanning cannot be stopped.
IllegalStateException
- if the Player
is in the CLOSED state.public void setBarcodeDecoder(BarcodeDecoder decoder) throws IllegalArgumentException
BarcodeDecoder
. This method can be called if scanning has already been started.
decoder
- The barcode decoder.
IllegalArgumentException
- if decoder is null
.ImageScanner.setDecoder(net.rim.device.api.amms.control.camera.ImageDecoder)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal