Moseycode Intents

The Moseycode application can be invoked from Android applications for the purpose of reading barcodes. Execution is temporarily ceded to Moseycode (by launching a sub-activity with a particular intent) for a user to scan a barcode at which point control is returned to the originating application along with information about the barcode(s) scanned. By design, the Moseycode user interface is completely uncluttered and should 'gel' with any style of application.

The application also attempts to launch an activity (using intents documented here) each time a user activates a barcode. This allows other applications to be launched automatically in response to particular barcodes. An intent is also broadcast each time a user activates a barcode from the Moseycode application; applications can use this to conduct background tasks too.

SCAN_BARCODE

Intent Actions

There is one action that can be used to invoke Moseycode as a sub activity:

com.tomgibara.intent.SCAN_BARCODE

Behaviour of the Moseycode activity is customized via the data URI and extras bundle.

Data URIs

The data URI of the intent specifies the source of the image(s) to be scanned for barcodes. At present four schemes are supported:

http/https
downloads an image over HTTP. The image format must be supported by the Android platform (at present JPEG or PNG).
content
uses the Android platform's content URI system to obtain the image data. Moseycode will obtain an the image via getContentResolver().openInputStream(data). The image format used must be one supported by the Android platform.
property
obtains an image as a Bitmap that has been stored as a property of the intent's extras bundle. For example, for the URI property://photo Moseycode will obtain the image data via (Bitmap) intent.getExtra("photo"). Note: Subject to future feedback on performance and memory usage, this scheme may be removed.
camera
obtains a sequence of images from the device's camera. The URI camera://0 refers to the primary camera on the device. Since the Android platform does not currently support multiple camera devices, this is the only valid URI.
File URLs (file://) are not currently supported, support has been deferred until anticipated changes to the operation of the Android file system have been published.

Note that for any of the above schemes, a data type must be specified so that the intent will match the Moseycode IntentFilter. In the case of the http and content schemes, the image mime type should be used (eg. image/jpeg or image/png) otherwise image/* should be used.

In the case of moving images (ie. from a camera) the Moseycode activity will not finish until a barcode has been resolved (or the user cancels the activity by pressing the back button). For still images the activity will will finish if no barcode is located immediately.

Extra Parameters

The Moseycode activity can be further customized by supplying extra parameters to the Intent used to launch it.

com.tomgibara.intent.scanMessage (type: String)
Provides a messages that is overlayed onto the screen while Moseycode is searching for barcodes. This can be used by applications to instruct the user within the context of their application.
com.tomgibara.intent.scanReturn (type: String)
Indicates the degree of barcode information that the invoking application wants returned. There are three supported values:
"CODE"
Returns the unique portal code associated with each barcode scanned. In the case of non-Moseycode barcodes, a pseudo-unique code is generated by digesting the barcode text.
"SOURCE"
Returns the text that is the content of the barcode. In the case of Moseycode barcodes, this is the XML generated from the fully resolved chamber document.
"DATA" (default value)
Returns a URI that encodes the primary barcode information. Many barcodes will contain more information than can be encapsulated in this way. For example, a barcode might contain a contact telephone number and email address, only one of which can be returned a URI. An attempt is made to return the most important data.
com.tomgibara.intent.scanContinuous (type: String)
A space delimited list of the barcode formats that should be continuously scanned by the application. At present, the only supported format is "MOSEYCODE". Supplying an empty string indicates that no formats should be considered. Not supplying a value indicates that all formats should be considered.
com.tomgibara.intent.scanContinuous (type: String)
A space delimited list of the barcode formats that should be scanned for by the application when a scan is requested by the user (unless the data source provides a constant image in which case the scan is performed automatically). At present, supported formats are:
  • QR_CODE
  • UPC_E
  • UPC_A
  • EAN_8
  • EAN_13
  • CODE_128
  • CODE_39
Supplying an empty string indicates that no formats should be considered. Not supplying a value indicates that all formats should be considered.

Activity Results

If the Moseycode activity doesn't fail (in the context of the Activity system). The results of the barcode scan will be communicated in the extras bundle passed to the Activity.onActivityResult method.

The bundle will contain a property named com.tomgibara.intent.barcodes which contains an array of android.os.Bundle objects, one for each barcode identified. If no barcodes were found, the array will be empty. The order in which barcodes are reported is undefined.

The properties of each Bundle provide information relating to a particular barcode. The following properties are supplied:

com.tomgibara.intent.barcodeFormat (type: String)
The type of barcode scanned, this will always be one of the supported formats (see above) and will be restricted to the formats requested by the com.tomgibara.intent.scanContinuous and com.tomgibara.intent.scanSnapshot properties.
com.tomgibara.intent.scanReturn (type: String)
The return type requested by the invoking application, or its default value "DATA"; provided as a convenience.
com.tomgibara.intent.portalChamberId (type: int)
Identifies a chamber – the digital contents of the barcode. This always has the value 0x100 for non-Moseycode barcodes
com.tomgibara.intent.portalShortData (type: short)
Provides 16 bits of supplementary information for the barcode; symbolic for non-Moseycode barcodes.
com.tomgibara.intent.portalIntData (type: int)
Provides a further 32 bits of supplementary information for the barcode; symbolic for non-Moseycode barcodes.
com.tomgibara.intent.portalChecksum (type: short)
A checksum derived from the chamberId, shortData and intData.
com.tomgibara.intent.barcodeSource (type: android.net.Uri)
The barcode data in the form of a Uri, may be null if no such representation is possible. This property is only available if the return type is either "SOURCE" or "DATA".
com.tomgibara.intent.barcodeUri (type: android.net.Uri)
The barcode data in the form of a Uri, may be null if no such representation is possible. This property is only available if the return type is "DATA".
com.tomgibara.intent.barcodeFlavors (type: String)
Contains a list of the barcode flavors known to be supported by the barcode. For more information about flavors, consult the documentation on chamber documents. Non-Moseycode barcodes are mapped onto the relevant flavor.

For some information about how to interpret the portal numbers see the Moseycode Encoding documentation. Of course, your application is free to interpret the data in any way that it wants.

As a convenience, the properties for the first listed barcode are applied to the intent's extras bundle directly. This makes it more straightforward to access the properties of a single scanned barcode.

ACTIVATE_BARCODE

Intent Actions

The following action is used by the Moseycode application to launch an activity at the time a user activates a barcode.

com.tomgibara.intent.ACTIVATE_BARCODE

If an intent filter of an external activity matches the intent, then the foreign application is assumed to be handling the activation and the Moseycode application will take no further actions; otherwise the default action is taken.

Data URIs

The data URI for the intent will be derived from the barcode data and may be null. Example schemes include http for barcoded links, mailto and tel for barcoded contact details.

Extra properties

The intent will host all of the extra properties that could be expected on a bundle that stores information about a single barcode (see above) with the exception of the com.tomgibara.intent.barcodeUri which provides the intent's data.

BARCODE_ACTIVATED

The following action is broadcast by the Moseycode application after a user has activated a barcode.

com.tomgibara.intent.BARCODE_ACTIVATED

All of the data and extras associated with this action are identical to those for the ACTIVATE_BARCODE action.

Usage Examples

A fully documented sample Android application that demonstrates how to use Moseycode in your own applications is provided with this release. See the release page for links to download the demo application and its source code.