Package | com.distriqt.extension.scanner |
Class | public final class Scanner |
Inheritance | Scanner flash.events.EventDispatcher |
This class represents the scanner extension.
The scanner creates an interface using the camera to scan for codes such as QR Codes, bar codes and other such encoded information. It supports many popular symbologies (types of bar codes) including EAN-13/UPC-A, UPC-E, EAN-8, Code 128, Code 39, Interleaved 2 of 5 and QR Code. However the particular support will be determined by the underlying algorithm in use.
The extension currently supports the following algorithms for code detection:
There are two main modes of operation, continuous and single result. Continuous mode
is the default mode. In this mode the scanner will continually scan for symbols and
return events whenever a symbol is found. The single result mode will close the scanner
as soon as one symbol is found and returned. Single result mode is enabled by setting the
singleResult
option to be true
as below:
var options:ScannerOptions = new ScannerOptions(); options.singleResult = true; Scanner.service.startScan( options );
The scanner interface contains two optional areas, with text labels and buttons. The
text in these areas are controlled by strings in the options class passed to the
startScan
function.
ScannerOptions.heading
ScannerOptions.message
ScannerOptions.cancelLabel
An Android application will require the following manifest additions to the application descriptor.
<android> <manifestAdditions><![CDATA[ <manifest android:installLocation="auto"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.CAMERA"/> <uses-feature android:name="android.hardware.camera" /> <application> <activity android:screenOrientation="portrait" android:name="com.distriqt.extension.scanner.zbar.ZBarScannerActivity" /> </application> </manifest> ]]></manifestAdditions> </android>
Property | Defined By | ||
---|---|---|---|
implementation : String [read-only]
The implementation currently in use. | Scanner | ||
isSupported : Boolean [static] [read-only]
Whether the current device supports the extensions functionality
| Scanner | ||
nativeVersion : String [read-only]
The native version string of the native extension. | Scanner | ||
service : Scanner [static] [read-only]
The singleton instance of the Scanner class. | Scanner | ||
version : String [read-only]
The version of this extension. | Scanner |
Method | Defined By | ||
---|---|---|---|
Scanner()
Constructor
You should not call this directly, but instead use the singleton access
| Scanner | ||
authorisationStatus():String
Retrieves the current authorisation status of this application. | Scanner | ||
dispose():void
Disposes the extension and releases any allocated resources. | Scanner | ||
Retrieves information about the scanning algorithm currently being
used in the native code. | Scanner | ||
hasAccess():Boolean
Helper method to determine if the current application has access to the device camera
| Scanner | ||
init(key:String):void Deprecated: You no longer need to use an application key [static]
Initialises the extension class for use with the provided key. | Scanner | ||
isScanning():Boolean
Determines if the scanner is currently in operation and displayed to the user. | Scanner | ||
requestAccess():Boolean
Performs a simple operation to display the permission dialog. | Scanner | ||
scanBitmap(bitmap:BitmapData):Array
Scans the supplied bitmap data for any symbols. | Scanner | ||
setScanBitmapOptions(options:ScannerOptions):void
Sets the scanner options to use for any scanBitmap calls. | Scanner | ||
setScanViewport(frame:Rectangle):Boolean
Updates the scanner viewport to the specified area. | Scanner | ||
startScanActivity(uiOptions:ActivityOptions = null, scannerOptions:ScannerOptions = null, cameraOptions:CameraOptions = null):Boolean
Starts the fullscreen scanning activity with options specified. | Scanner | ||
startScanInViewport(viewportOptions:ViewportOptions, scannerOptions:ScannerOptions = null, cameraOptions:CameraOptions = null):Boolean
Starts a scanner process contained within the specified viewport. | Scanner | ||
stopScan():Boolean
Stops the current scan process (if running). | Scanner |
Constant | Defined By | ||
---|---|---|---|
EXT_CONTEXT_ID : String = com.distriqt.Scanner [static] | Scanner | ||
VERSION : String = 5.1.0 [static] | Scanner |
implementation | property |
implementation:String
[read-only]
The implementation currently in use. This should be one of the following depending on the platform in use and the functionality supported by this extension:
Android
iOS
default
unknown
public function get implementation():String
isSupported | property |
isSupported:Boolean
[read-only] Whether the current device supports the extensions functionality
public static function get isSupported():Boolean
nativeVersion | property |
nativeVersion:String
[read-only]
The native version string of the native extension.
public function get nativeVersion():String
service | property |
service:Scanner
[read-only] The singleton instance of the Scanner class.
public static function get service():Scanner
Error — If there was a problem creating or accessing the extension, or if the developer key is invalid
|
version | property |
version:String
[read-only]
The version of this extension.
This should be of the format, MAJOR.MINOR.BUILD
public function get version():String
Scanner | () | Constructor |
public function Scanner()
Constructor You should not call this directly, but instead use the singleton access
authorisationStatus | () | method |
public function authorisationStatus():String
Retrieves the current authorisation status of this application.
There are several possible values as defined in the AuthorisationStatus
class.
String — The AuthorisationStatus string
|
See also
dispose | () | method |
public function dispose():void
Disposes the extension and releases any allocated resources. Once this function
has been called, a call to init
is neccesary again before any of the
extensions functionality will work.
getScannerInfo | () | method |
public function getScannerInfo():ScannerInfo
Retrieves information about the scanning algorithm currently being used in the native code.
ReturnsScannerInfo — A scanner information object with details about the algorithm
|
hasAccess | () | method |
public function hasAccess():Boolean
Helper method to determine if the current application has access to the device camera
ReturnsBoolean |
init | () | method |
public static function init(key:String):void
Initialises the extension class for use with the provided key.
Parameters
key:String |
Error — If there was a problem creating or accessing the extension, or if the key is invalid
|
isScanning | () | method |
public function isScanning():Boolean
Determines if the scanner is currently in operation and displayed to the user.
ReturnsBoolean — true if the scanner is in operation and false otherwise
|
requestAccess | () | method |
public function requestAccess():Boolean
Performs a simple operation to display the permission dialog.
Note this will only be shown if the authorisation status is currently NOT_DETERMINED
You do not need to call this function, it just allows you to control when the permission dialog is presented. If you don't call this function then the permission dialog will be displayed just before your first access camera.
ReturnsBoolean |
scanBitmap | () | method |
public function scanBitmap(bitmap:BitmapData):Array
Scans the supplied bitmap data for any symbols. The resulting array
will contain ScanResult
objects representing any symbols found in the image.
Parameters
bitmap:BitmapData — The bitmap data to scan
|
Array — An array of ScanResult objects. May be empty if none were found.
|
setScanBitmapOptions | () | method |
public function setScanBitmapOptions(options:ScannerOptions):void
Sets the scanner options to use for any scanBitmap
calls.
Parameters
options:ScannerOptions |
setScanViewport | () | method |
public function setScanViewport(frame:Rectangle):Boolean
Updates the scanner viewport to the specified area.
Parameters
frame:Rectangle — The new viewport rectangle to use
|
Boolean — true if successful and false if the scanner was not running in viewport mode
|
startScanActivity | () | method |
public function startScanActivity(uiOptions:ActivityOptions = null, scannerOptions:ScannerOptions = null, cameraOptions:CameraOptions = null):Boolean
Starts the fullscreen scanning activity with options specified.
Parameters
uiOptions:ActivityOptions (default = null ) — Options for the UI elements of the scanner
| |
scannerOptions:ScannerOptions (default = null ) — The options to start the scanner with
| |
cameraOptions:CameraOptions (default = null ) — Options for the camera (device, etc)
|
Boolean — true if the scanner was started successfully and false otherwise
|
startScanInViewport | () | method |
public function startScanInViewport(viewportOptions:ViewportOptions, scannerOptions:ScannerOptions = null, cameraOptions:CameraOptions = null):Boolean
Starts a scanner process contained within the specified viewport. The viewport will contain a camera preview overlay
Parameters
viewportOptions:ViewportOptions — Options describing the viewport for the scanner
| |
scannerOptions:ScannerOptions (default = null ) — The options to start the scanner with
| |
cameraOptions:CameraOptions (default = null ) — Options for the camera (device, etc)
|
Boolean — true if the scanner was started successfully and false otherwise
|
stopScan | () | method |
public function stopScan():Boolean
Stops the current scan process (if running). If the current process is a fullscreen activity then it is closed and focus returned to the application. If the current process is a viewport scan then the view is removed and the scan process stopped.
ReturnsBoolean — true if the scanner was running and stopped successfully and false if it wasn't running.
|
EXT_CONTEXT_ID | Constant |
public static const EXT_CONTEXT_ID:String = com.distriqt.Scanner
VERSION | Constant |
public static const VERSION:String = 5.1.0
The following example shows the basic usage of the extension, creating a scanning interface and listening for detected QR codes. It limits the scan to the first found code and will close after a code is found.
Scanner.init( DEV_KEY ); if (Scanner.isSupported) { Scanner.service.addEventListener( ScannerEvent.CODE_FOUND, scanner_codeFoundHandler, false, 0, true ); var options:ScannerOptions = new ScannerOptions(); options.symbologies = [ Symbology.QRCODE ]; options.singleResult = true; Scanner.service.startScan( options ); } ... private function scanner_codeFoundHandler( event:ScannerEvent ):void { trace( "code found: " + event.data ); }