Warning Older Docs! - You are viewing documentation for a previous released version of RhoMobile Suite.

Barcode API

Allows the device to recognize a barcode. See the controller and view in the /app/BarcodeRecognizer folder of the System API Samples application for an example.

See Barcode in Device Capabilities for a discussion of barcode recognition.

As of Rhodes version 3.3.3, the Barcode, is removed from Rhodes. This feature is only supported in Zebra RhoMobile Suite. If you wish to use this feature, you will need to upgrade to RhoMobile Suite. Your application’s build.yml will also need to be modified to indicate the application type is ‘Rhoelements’. Additionally, a RhoElements license is required.

Using JavaScript API

You can call some of the Barcode methods from JavaScript as well as Ruby. To use the JavaScript API, add the public/js/rho_javascript_api.js file — created at build time as part of the application package — to the .html, .erb, or .js file calling the JavaScript method.

The JavaScript API methods with a return value can pass it as a parameter in jQuery-compatible continuation (deferred object, a kind of callback). Possible continuations to handle are done, fail, and complete.

Rho.Class.method(params).done(function(handler) { /* handler... */ })

You must enable JavaScript by putting rho-javascript into extensions in your build.yml.

extensions: ["rho-javascript"]

You must have a RhoElements license to use the JavaScript API.

Enabling Barcode Recognition

You need to enable the camera on the device. Do this by adding that capability to the build.yml file:

capabilities:
  - camera

On iPhone, Android, Windows Mobile, and Blackberry (iphone, android, wm, bb), you need to add the barcode extension:

:iphone
  extensions: ["barcode"]

barcode_recognize

Recognizes a barcode on an image. Returns a string with recognized code, or empty string if the barcode is not recognized.

Ruby Syntax:

Barcode.barcode_recognize(image_file_full_path)

JavaScript syntax:

Rho.Barcode.barcode_recognize(image_file_full_path)
image_file_full_path String. Path to the image that contains the barcode to be recognized.

take_barcode

iPhone and Android only (not supported on iPhone 2G and iPhone 3G). Open a user interface for real-time barcode recognition from the device camera. If a barcode is found, the user can confirm barcode recognition, or continue to try to recognize the barcode. When the user confirms or cancels, the callback is called.

Ruby syntax:

Barcode.take_barcode(url_for :action => :take_callback)
Barcode.take_barcode(url_for(:action => :take_callback), {hash_of_params})

JavaScript syntax:

Rho.Barcode.take_barcode(callback_function)
Rho.Barcode.take_barcode(callback_function, params)

An example of params (camera or deviceName) can be camera: "front".

Android only. You can also use the front camera for take_barcode.

Barcode.take_barcode(url_for(:action => :take_callback), {:camera => 'front'})

You can optionally specify a specific device scanner (ex: the device may have a 1D laser scanner and a camera – both are capable of scanning barcodes), otherwise the first available scanner object will be used.

Barcode.take_barcode(url_for(:action => :barcode_callback), {:deviceName=>deviceName_from_enumerate})

The callback receives these parameters:

status OK or CANCEL
barcode The string for the recognized barcode.

enumerate

Get a list of scanners present on the device. Returns an array of hashes (‘name’,‘id’).

Barcode.enumerate(url_for(:action => :enumerate_callback))

Callback parameters:

  • scannerArray – array of Hashes(“deviceName”,“friendlyName”)

enable

Enables the scanner. barcode_callback gets the same parameters as Barcode.take_barcode.

Barcode.enable(url_for(:action => :barcode_callback), {:deviceName=>deviceName_from_enumerate})

Callback parameters:

  • “status” – “ok” or “cancel”.
  • “barcode” – the recognized barcode string.

disable

Disables the currently enabled scanner. This reverts the scanner to its default state and flushes any current decoder settings.

Barcode.disable

start

Performs a soft trigger start. If the scan does not result in a decode it is necessary to perform a soft stop before another soft start .

Barcode.start

stop

Performs a soft trigger stop.

Barcode.stop 
Back to Top