Skip to content
Titanium SDK

ti.barcode

QR and Barcode Scanner

API reference

Compiled from

Modules.Barcode

moduleAndroidiPhoneiPadsince Android 3.1.0, iPhone 3.2.0, iPad 3.2.0

Extends Titanium.Module

Add-on Barcode module

System Requirements

  • Titanium SDK 5.5.1+
  • Camera Permissions set in your tiapp.xml:
<ti:app>
  <!-- ... -->
  <ios>
    <plist>
      <dict>
        <key>NSCameraUsageDescription</key>
        [string](api:Global.String)We need permission to access your device camera.</string>
      </dict>
    </plist>
  </ios>
  <!-- ... -->
</ti:app>

Properties 37

allowInstructions

BooleanAndroidsince 3.1.0

Whether or not to display helpful instructions or a changelog when the app is updated.

Default: true

allowMenu

BooleanAndroidsince 3.1.0

Whether or not to allow the built-in ZXing menu to display.

Default: true

allowRotation

BooleandeprecatediPhoneiPad

Deprecated since 2.0.0, removed in 2.0.0

Value that indicates if the barcode capture should analyze captured images in either portrait or landscape device orientation. (Warning: Analyzing both the captured image and the rotated version(s) of the image will increase the processing time of the capture.)

  • true: Captured images will be analyzed in both portrait and landscape orientation.
  • false [default]: Captured images will be analyzed using only the current device orientation.

Default: false

BOOKMARK

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

CALENDAR

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

CONTACT

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

copyToClipboard

BooleanAndroidsince 6.1.0

Whether or not copy the result to the clipboard

Default: false

displayedMessage

Stringsince 3.1.0

Controls the message that is displayed to the end user when they are capturing a barcode.

EMAIL

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

FORMAT_MAXICODE

Numbersince 3.1.0read-only

Used in the capture and parse methods and the success event to specify accepted formats.

Please note that Maxicode support is considered Beta, and requires using the pureBarcode hint.

FORMAT_NONE

Numberdeprecatedsince 3.1.0read-only

Deprecated since 5.0.0

Used in the capture and parse methods and the success event to specify accepted formats.

GEOLOCATION

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

SMS

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

TELEPHONE

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

TEXT

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

UNKNOWN

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

URL

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

useFrontCamera

Booleansince 3.1.0

Controls whether or not the front camera on the device will be used to capture barcodes. On Android, this requires API level 9 (Android OS 2.3) or higher. If no front camera is available, this will gracefully fall back to utilize whatever camera is available.

Default: false

useLED

Booleansince 3.1.0

Whether or not to use the LED when scanning barcodes (also known as the flashlight, torch, or some derivation thereof).

Default: false

WIFI

Numbersince 3.1.0read-only

Used in the success event to specify the assumed content type of the barcode.

Methods 4

cancel

since 3.1.0

Cancels and closes the currently open capture window.

canShow

deprecatediPhoneiPad

Deprecated since 2.0.0

Whether the barcode scanner camera is allowed.

Returns Boolean

capture

since 3.1.0

Brings up the camera and begins the capture sequence for processing a barcode.

Parameters
ParametersTypeDescription
dictionary?BarcodeCaptureDict

optional

19 fields
acceptedFormats? Array<Number>

An optional array of int constants detailing which barcode formats are accepted. Defaults to all formats. Check out the "Barcode Format Constants" section below to see the available int constants.

allowedEANExtensions? Array<Number>

An optional int[] that specifies allowed extension lengths for EAN or UPC barcodes. https://zxing.github.io/zxing/apidocs/

allowedLengths? Array<Number>

An optional int[] that specifies allowed lengths of encoded data -- reject anything else. https://zxing.github.io/zxing/apidocs/

animate? Boolean

Indicates if the device should animate between the current activity and the camera activity when the current activity is in a different orientation than the camera. Default is true.

assumeCode39CheckDigit? Boolean

An optional boolean which if true, will assume Code 39 codes employ a check digit. https://zxing.github.io/zxing/apidocs/

Please note that this hint only applies to CODE_39 format barcodes.

assumeGS1? Boolean

An optional boolean to assume the barcode is being processed as a GS1 barcode, and modify behavior as needed. https://zxing.github.io/zxing/apidocs/

Please note that this hint only applies to CODE_128 format barcodes.

characterSet? String

An optional string that specifies what character encoding to use when decoding, where applicable https://zxing.github.io/zxing/apidocs/

frameHeight? Number

Height of the rectangle that is shown in the scanner

frameWidth? Number

Width of the rectangle that is shown in the scanner

keepOpen? Boolean

Whether or not to keep the barcode scanner open after a barcode is recognized. Defaults to false. When set to true, "success" will fire once every time a barcode is recognized, up to two times per second. As such, it can fire multiple times for a single barcode!

overlay? Titanium.UI.View

The view to lay on top of the camera activity.

preventRotation? Boolean

Prevent the scanner from auto-rotating when the device is rotated. Default: true

pureBarcode? Boolean

An optional boolean to assume the image is a pure monochrome image of a barcode. https://zxing.github.io/zxing/apidocs/

resultDuration? Number

Time in milliseconds that the result will be visible after a scan.

returnCodabarStartEnd? Boolean

An optional boolean which if true, will return the start and end digits in a Codabar barcode instead of stripping them. https://zxing.github.io/zxing/apidocs/

Please note that this hint only applies to CODABAR format barcodes.

showCancel? Boolean

Whether or not to include the default cancel button. Defaults to true.

showInfoText? Boolean

Whether to show informational text

showRectangle? Boolean

Whether or not to include the default rectangle around the scanning area. Defaults to true.

tryHarder? Boolean

An optional boolean to spend more time to try to find a barcode; optimize for accuracy, not speed. https://zxing.github.io/zxing/apidocs/

parse

since 3.1.0

Parses a blob image for barcodes.

Parameters
ParametersTypeDescription
dictionary?BarcodeParseDict

optional

10 fields
acceptedFormats? Array<Number>

An optional array of int constants detailing which barcode formats are accepted. Defaults to all formats. Check out the "Barcode Format Constants" section below to see the available int constants.

allowedEANExtensions? Array<Number>

An optional int[] that specifies allowed extension lengths for EAN or UPC barcodes. https://zxing.github.io/zxing/apidocs/

allowedLengths? Array<Number>

An optional int[] that specifies allowed lengths of encoded data -- reject anything else. https://zxing.github.io/zxing/apidocs/

assumeCode39CheckDigit? Boolean

An optional boolean which if true, will assume Code 39 codes employ a check digit. https://zxing.github.io/zxing/apidocs/

Please note that this hint only applies to CODE_39 format barcodes.

assumeGS1? Boolean

An optional boolean to assume the barcode is being processed as a GS1 barcode, and modify behavior as needed. https://zxing.github.io/zxing/apidocs/

Please note that this hint only applies to CODE_128 format barcodes.

characterSet? String

An optional string that specifies what character encoding to use when decoding, where applicable https://zxing.github.io/zxing/apidocs/

image Titanium.Blob

The image blob to parse for a barcode.

pureBarcode? Boolean

An optional boolean to assume the image is a pure monochrome image of a barcode. https://zxing.github.io/zxing/apidocs/

returnCodabarStartEnd? Boolean

An optional boolean which if true, will return the start and end digits in a Codabar barcode instead of stripping them. https://zxing.github.io/zxing/apidocs/

Please note that this hint only applies to CODABAR format barcodes.

tryHarder? Boolean

An optional boolean to spend more time to try to find a barcode; optimize for accuracy, not speed. https://zxing.github.io/zxing/apidocs/

Events 3

Fired upon a successful barcode scan.

Event properties
Event propertiesTypeDescription
formatString | Number

The format of the barcode. Reported with a value of one of the Modules.Barcode.FORMAT_* constant if matching a known format. Otehrwise, may report a string value.

resultString

The raw contents of the barcode

codeNumber

The activity result code from the scanning activity. Use the result constants defined in the Ti.Android namespace

Titanium.Android.RESULT_CANCELED, Titanium.Android.RESULT_FIRST_USER, or Titanium.Android.RESULT_OK

contentTypeNumber

The type of barcode content. Use the constants defined in this module to determine which.

dataObject

The parsed fields associated with the contentType.

bytesTitanium.Buffer

The raw byte array contents of the barcode, when available